-
Notifications
You must be signed in to change notification settings - Fork 7
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
83 changed files
with
1,536 additions
and
905 deletions.
There are no files selected for viewing
Large diffs are not rendered by default.
Oops, something went wrong.
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
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 |
---|---|---|
@@ -0,0 +1,19 @@ | ||
#[generate_trait] | ||
pub impl BoolImpl<T, +Drop<T>> of BoolTrait<T> { | ||
/// Returns `Some(t)` if the `bool` is `true`, or `None` otherwise. | ||
/// | ||
/// # Examples | ||
/// | ||
/// ``` | ||
/// assert(false.then_some(0) == Option::None); | ||
/// assert(true.then_some(0) == Option::Some(0)); | ||
/// ``` | ||
#[inline(always)] | ||
fn then_some(self: bool, t: T) -> Option<T> nopanic { | ||
if self { | ||
Option::Some(t) | ||
} else { | ||
Option::None | ||
} | ||
} | ||
} |
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,20 +1,34 @@ | ||
#[derive(Copy, Drop)] | ||
extern type Box<T>; | ||
pub extern type Box<T>; | ||
|
||
// These functions are only exposed in the corelib through the trait below since calling them | ||
// directly with tuples panics due to auto unpacking of the tuple. | ||
// TODO(Gil): Expose in the core lib when the described behaviour is fixed. | ||
extern fn into_box<T>(value: T) -> Box<T> nopanic; | ||
extern fn unbox<T>(box: Box<T>) -> T nopanic; | ||
extern fn box_forward_snapshot<T>(value: @Box<T>) -> Box<@T> nopanic; | ||
|
||
#[generate_trait] | ||
impl BoxImpl<T> of BoxTrait<T> { | ||
pub impl BoxImpl<T> of BoxTrait<T> { | ||
#[inline(always)] | ||
#[must_use] | ||
fn new(value: T) -> Box<T> nopanic { | ||
into_box(value) | ||
} | ||
#[inline(always)] | ||
#[must_use] | ||
fn unbox(self: Box<T>) -> T nopanic { | ||
unbox(self) | ||
} | ||
#[must_use] | ||
fn as_snapshot(self: @Box<T>) -> Box<@T> nopanic { | ||
box_forward_snapshot(self) | ||
} | ||
} | ||
|
||
impl BoxDebug<T, impl TDebug: core::fmt::Debug<T>> of core::fmt::Debug<Box<T>> { | ||
fn fmt(self: @Box<T>, ref f: core::fmt::Formatter) -> Result<(), core::fmt::Error> { | ||
write!(f, "&")?; | ||
TDebug::fmt(self.as_snapshot().unbox(), ref f) | ||
} | ||
} |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,5 @@ | ||
trait Clone<T> { | ||
pub trait Clone<T> { | ||
#[must_use] | ||
fn clone(self: @T) -> T; | ||
} | ||
|
||
|
Oops, something went wrong.