Impl 'Clone' for 'State'.

Resolves #1411.
This commit is contained in:
Jonty 2020-10-02 22:54:11 +13:00 committed by Sergio Benitez
parent a6f5a63535
commit b7565172eb
1 changed files with 19 additions and 0 deletions

View File

@ -183,3 +183,22 @@ impl<T: Send + Sync + 'static> Deref for State<'_, T> {
self.0
}
}
impl<T: Send + Sync + 'static> Clone for State<'_, T> {
fn clone(&self) -> Self {
State(self.0)
}
}
#[cfg(test)]
mod tests {
#[test]
fn state_is_cloneable() {
struct Token(usize);
let rocket = crate::ignite().manage(Token(123));
let state = rocket.state::<Token>().unwrap();
assert_eq!(state.0, 123);
assert_eq!(state.clone().0, 123);
}
}