Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merge std and core libraries #6729

Draft
wants to merge 21 commits into
base: master
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5,377 changes: 0 additions & 5,377 deletions sway-lib-core/src/codec.sw

Large diffs are not rendered by default.

74 changes: 0 additions & 74 deletions sway-lib-core/src/never.sw
Original file line number Diff line number Diff line change
@@ -1,75 +1 @@
library;

use ::ops::{Eq, Not, Ord};

/// `!` represents the type of computations which never resolve to any value at all.
///
/// # Additional Information
///
/// `break`, `continue` and `return` expressions also have type `!`. For example we are allowed to
/// write:
///
/// ```sway
/// let x: ! = {
/// return 123
/// };
/// ```
///
/// Although the `let` is pointless here, it illustrates the meaning of `!`. Since `x` is never
/// assigned a value (because `return` returns from the entire function), `x` can be given type
/// `Never`. We could also replace `return 123` with a `revert()` or a never-ending `loop` and this code
/// would still be valid.
///
/// A more realistic usage of `Never` is in this code:
///
/// ```sway
/// let num: u32 = match get_a_number() {
/// Some(num) => num,
/// None => break,
/// };
/// ```
///
/// Both match arms must produce values of type [`u32`], but since `break` never produces a value
/// at all we know it can never produce a value which isn't a [`u32`]. This illustrates another
/// behaviour of the `!` type - expressions with type `!` will coerce into any other type.
///
/// Note that `!` type coerces into any other type, another example of this would be:
///
/// ```sway
/// let x: u32 = {
/// return 123
/// };
/// ```
///
/// Regardless of the type of `x`, the return block of type `Never` will always coerce into `x` type.
///
/// # Examples
///
/// ```sway
/// fn foo() {
/// let num: u64 = match Option::None::<u64> {
/// Some(num) => num,
/// None => return,
/// };
/// }
/// ```
impl Not for ! {
fn not(self) -> Self {
match self {}
}
}

impl Eq for ! {
fn eq(self, _other: Self) -> bool {
self
}
}

impl Ord for ! {
fn gt(self, _other: Self) -> bool {
self
}
fn lt(self, _other: Self) -> bool {
self
}
}
Loading
Loading