xref: /aosp_15_r20/bootable/libbootloader/gbl/libgbl/src/fastboot/shared.rs (revision 5225e6b173e52d2efc6bcf950c27374fd72adabc)
1 // Copyright 2024, The Android Open Source Project
2 //
3 // Licensed under the Apache License, Version 2.0 (the "License");
4 // you may not use this file except in compliance with the License.
5 // You may obtain a copy of the License at
6 //
7 //     http://www.apache.org/licenses/LICENSE-2.0
8 //
9 // Unless required by applicable law or agreed to in writing, software
10 // distributed under the License is distributed on an "AS IS" BASIS,
11 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 // See the License for the specific language governing permissions and
13 // limitations under the License.
14 
15 use core::{
16     cell::RefCell,
17     ops::{Deref, DerefMut},
18 };
19 
20 /// A shared instance guarded by `RefCell`.
21 pub struct Shared<T>(RefCell<T>);
22 
23 impl<T> From<T> for Shared<T> {
from(val: T) -> Self24     fn from(val: T) -> Self {
25         Shared(val.into())
26     }
27 }
28 
29 impl<T> Deref for Shared<T> {
30     type Target = RefCell<T>;
31 
deref(&self) -> &Self::Target32     fn deref(&self) -> &Self::Target {
33         &self.0
34     }
35 }
36 
37 impl<T> DerefMut for Shared<T> {
deref_mut(&mut self) -> &mut Self::Target38     fn deref_mut(&mut self) -> &mut Self::Target {
39         &mut self.0
40     }
41 }
42