Skip to content

How do I use guard transparency with references? #2438

Discussion options

You must be logged in to vote

You are able to return references safely! This is what lifetimes are for. You simply need to let the type system know where the reference comes from. You do this using a lifetime annotation:

fn f<'r>(v: &'r T) -> &'r T
{ v }

Applied to request guards, your guard would need to hold a reference to the request. This implies that the guard's type must have a lifetime generic. Then simply concretize the generic as the lifetime of the request in the impl and Rust should take care of the rest.

Replies: 2 comments 5 replies

Comment options

You must be logged in to vote
0 replies
Comment options

You must be logged in to vote
5 replies
@buehler
Comment options

@buehler
Comment options

@SergioBenitez
Comment options

@the10thWiz
Comment options

@buehler
Comment options

Answer selected by buehler
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
3 participants