Skip to content
Discussion options

You must be logged in to vote

scoped is a little hard to grasp if you don't understand the concept of "lifetimes". It essentially means that the pointer value of the reference (or span) will not be used anywhere past the end of the containing method. The data may live longer if it's copied elsewhere. So, for AppendFormatted, since it copies the data from the span into a different buffer, the span's lifetime can be as small as the method.

There's a nice answer on StackOverflow that tries to explain it.


Someone correct me if I'm wrong, but I'm pretty sure it's similar to the following Rust lifetime annotations (note the lack of where 'a : 'b bounds):

pub fn append_formatted<'a, 'b>(&'a self, value: &'b [u8]) {
    // ...

Replies: 1 comment 5 replies

Comment options

You must be logged in to vote
5 replies
@kyoyama-kazusa
Comment options

@kyoyama-kazusa
Comment options

@colejohnson66
Comment options

@CyrusNajmabadi
Comment options

@kyoyama-kazusa
Comment options

Answer selected by kyoyama-kazusa
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
3 participants