-
Notifications
You must be signed in to change notification settings - Fork 1.6k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[
once_cell_lazy
]: adjust error message, docs, and auxiliary code.
- Loading branch information
Showing
7 changed files
with
79 additions
and
108 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,52 +1,39 @@ | ||
//! **FAKE** once_cell crate. | ||
pub mod sync { | ||
use core::cell::Cell; | ||
use std::marker::PhantomData; | ||
|
||
pub struct OnceCell<T>(PhantomData<T>); | ||
impl<T> OnceCell<T> { | ||
pub const fn new() -> OnceCell<T> { | ||
OnceCell(PhantomData) | ||
} | ||
} | ||
impl<T> Default for OnceCell<T> { | ||
fn default() -> Self { | ||
Self::new() | ||
} | ||
} | ||
|
||
pub struct Lazy<T, F = fn() -> T> { | ||
cell: OnceCell<T>, | ||
init: Cell<Option<F>>, | ||
cell: PhantomData<T>, | ||
init: F, | ||
} | ||
unsafe impl<T, F: Send> Sync for Lazy<T, F> where OnceCell<T>: Sync {} | ||
unsafe impl<T, F: Send> Sync for Lazy<T, F> {} | ||
impl<T, F> Lazy<T, F> { | ||
pub const fn new(f: F) -> Lazy<T, F> { | ||
Lazy { | ||
cell: OnceCell::new(), | ||
init: Cell::new(Some(f)), | ||
cell: PhantomData, | ||
init: f, | ||
} | ||
} | ||
|
||
pub fn into_value(this: Lazy<T, F>) -> Result<T, i32> { | ||
Err(1) | ||
pub fn into_value(this: Lazy<T, F>) -> Result<T, F> { | ||
unimplemented!() | ||
} | ||
|
||
pub fn force(_this: &Lazy<T, F>) -> i32 { | ||
0 | ||
pub fn force(_this: &Lazy<T, F>) -> &T { | ||
unimplemented!() | ||
} | ||
|
||
pub fn force_mut(_this: &mut Lazy<T, F>) -> i32 { | ||
0 | ||
pub fn force_mut(_this: &mut Lazy<T, F>) -> &mut T { | ||
unimplemented!() | ||
} | ||
|
||
pub fn get(_this: &Lazy<T, F>) -> i32 { | ||
0 | ||
pub fn get(_this: &Lazy<T, F>) -> Option<&T> { | ||
unimplemented!() | ||
} | ||
|
||
pub fn get_mut(_this: &mut Lazy<T, F>) -> i32 { | ||
0 | ||
pub fn get_mut(_this: &mut Lazy<T, F>) -> Option<&mut T> { | ||
unimplemented!() | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.