Things we did:

  • :hatched_chick: Our blog post is published! :hatched_chick:
  • Headers API
    • Simplified Headers constructor and new function, and added fill function.
    • Started looking into how I should modify WebIDL.py to allow bindings generator to support default ByteString values.
  • Request API
    • (Malisa) Filed spec bug for request constructor.
    • Finally addressed all the comments from the Request API PR!

Things we learned:

Lifetime Error

Say you have a one line of code that is:

let method_string = init_method.clone().to_lower().as_str();

If you try to compile it, you may get an error that looks like: lifetime-error

The reason is that to_lower() gives back a String, and as_str() tries to give a reference to that String created by to_lower(). However, that String would not exist anymore because it was consumed by as_str() and therefore, the compiler throws an error saying that the borrowed value doesn’t live long enough.

To fix this issue, the compiler suggests using let binding to increase its life time. In other words, the one line code can be expanded as following:

let method_lower = init_method.to_lower();
let method_string = method_lower.as_str();

This way, as_str() can return a reference to the String (method_lower) which would exist in its scope, i.e. between curly brackets.

Similarly, this won’t compile and will throw lifetime errors:

DOMString::from_string(self.request.borrow().integrity_metadata.borrow().clone())

Again, it would try to borrow integrity_metadata from self.request which would be transformed to Ref<'_, net_traits::request::Request> after self.request.borrow(). This error can be resolved by expanding the code above to this:

let r = self.request.borrow();
let integrity = r.integrity_metadata.borrow();
DOMString::from_string(integrity.clone())

TODO:

  • Response:
    • Continue to work on Bindings generator.
    • Work on Constructor.
  • Request:
    • Wait for more comments.
  • General:
    • Finish up writing blog post, intro to Rust’s ownership.