Protocol

Struct Protocol 

Source
#[non_exhaustive]
pub struct Protocol { pub name: &'static str, pub method: Option<&'static str>, pub hash: Hash, /* private fields */ }
Expand description

A pre-defined protocol function.

§Examples

use rune::runtime::Protocol;

let protocol = Protocol::GET;
assert_eq!(protocol.name, "GET");

Fields (Non-exhaustive)§

This struct is marked as non-exhaustive
Non-exhaustive structs could have additional fields added in future. Therefore, non-exhaustive structs cannot be constructed in external crates using the traditional Struct { .. } syntax; cannot be matched against without a wildcard ..; and struct update syntax will not work.
§name: &'static str

The name of the builtin function.

§method: Option<&'static str>

If this protocol defines an associated method, this is the name of that method.

§hash: Hash

The hash of the builtin function.

Implementations§

Source§

impl Protocol

Source

pub const GET: Protocol

The function to access a field.

§Examples
use rune::hash::IntoHash;
use rune::runtime::Protocol;

 let hash = Protocol::GET.into_hash();
let protocol = Protocol::from_hash(hash);
 assert_eq!(protocol, Some(Protocol::GET));
Source

pub const SET: Protocol

The function to set a field.

§Examples
use rune::hash::IntoHash;
use rune::runtime::Protocol;

 let hash = Protocol::SET.into_hash();
let protocol = Protocol::from_hash(hash);
 assert_eq!(protocol, Some(Protocol::SET));
Source

pub const INDEX_GET: Protocol

The function to access an index.

§Examples
use rune::hash::IntoHash;
use rune::runtime::Protocol;

 let hash = Protocol::INDEX_GET.into_hash();
let protocol = Protocol::from_hash(hash);
 assert_eq!(protocol, Some(Protocol::INDEX_GET));
Source

pub const INDEX_SET: Protocol

The function to set an index.

§Examples
use rune::hash::IntoHash;
use rune::runtime::Protocol;

 let hash = Protocol::INDEX_SET.into_hash();
let protocol = Protocol::from_hash(hash);
 assert_eq!(protocol, Some(Protocol::INDEX_SET));
Source

pub const PARTIAL_EQ: Protocol

Check two types for partial equality.

§Examples
use rune::hash::IntoHash;
use rune::runtime::Protocol;

 let hash = Protocol::PARTIAL_EQ.into_hash();
let protocol = Protocol::from_hash(hash);
 assert_eq!(protocol, Some(Protocol::PARTIAL_EQ));
Source

pub const EQ: Protocol

Check two types for total equality.

§Examples
use rune::hash::IntoHash;
use rune::runtime::Protocol;

 let hash = Protocol::EQ.into_hash();
let protocol = Protocol::from_hash(hash);
 assert_eq!(protocol, Some(Protocol::EQ));
Source

pub const PARTIAL_CMP: Protocol

Perform an partial comparison between two values.

§Examples
use rune::hash::IntoHash;
use rune::runtime::Protocol;

 let hash = Protocol::PARTIAL_CMP.into_hash();
let protocol = Protocol::from_hash(hash);
 assert_eq!(protocol, Some(Protocol::PARTIAL_CMP));
Source

pub const GT: Protocol

The protocol behind the > operator.

§Examples
use rune::hash::IntoHash;
use rune::runtime::Protocol;

 let hash = Protocol::GT.into_hash();
let protocol = Protocol::from_hash(hash);
 assert_eq!(protocol, Some(Protocol::GT));
Source

pub const GE: Protocol

The protocol behind the >= operator.

§Examples
use rune::hash::IntoHash;
use rune::runtime::Protocol;

 let hash = Protocol::GE.into_hash();
let protocol = Protocol::from_hash(hash);
 assert_eq!(protocol, Some(Protocol::GE));
Source

pub const LT: Protocol

The protocol behind the > operator.

§Examples
use rune::hash::IntoHash;
use rune::runtime::Protocol;

 let hash = Protocol::LT.into_hash();
let protocol = Protocol::from_hash(hash);
 assert_eq!(protocol, Some(Protocol::LT));
Source

pub const LE: Protocol

The protocol behind the <= operator.

§Examples
use rune::hash::IntoHash;
use rune::runtime::Protocol;

 let hash = Protocol::LE.into_hash();
let protocol = Protocol::from_hash(hash);
 assert_eq!(protocol, Some(Protocol::LE));
Source

pub const MAX: Protocol

§Examples
use rune::hash::IntoHash;
use rune::runtime::Protocol;

 let hash = Protocol::MAX.into_hash();
let protocol = Protocol::from_hash(hash);
 assert_eq!(protocol, Some(Protocol::MAX));
Source

pub const MIN: Protocol

§Examples
use rune::hash::IntoHash;
use rune::runtime::Protocol;

 let hash = Protocol::MIN.into_hash();
let protocol = Protocol::from_hash(hash);
 assert_eq!(protocol, Some(Protocol::MIN));
Source

pub const CMP: Protocol

Perform an total comparison between two values.

§Examples
use rune::hash::IntoHash;
use rune::runtime::Protocol;

 let hash = Protocol::CMP.into_hash();
let protocol = Protocol::from_hash(hash);
 assert_eq!(protocol, Some(Protocol::CMP));
Source

pub const NEG: Protocol

The protocol for the unary negation operation.

§Examples
use rune::hash::IntoHash;
use rune::runtime::Protocol;

 let hash = Protocol::NEG.into_hash();
let protocol = Protocol::from_hash(hash);
 assert_eq!(protocol, Some(Protocol::NEG));
Source

pub const NOT: Protocol

The protocol for the unary not operation.

§Examples
use rune::hash::IntoHash;
use rune::runtime::Protocol;

 let hash = Protocol::NOT.into_hash();
let protocol = Protocol::from_hash(hash);
 assert_eq!(protocol, Some(Protocol::NOT));
Source

pub const ADD: Protocol

The protocol for the addition operation.

§Examples
use rune::hash::IntoHash;
use rune::runtime::Protocol;

 let hash = Protocol::ADD.into_hash();
let protocol = Protocol::from_hash(hash);
 assert_eq!(protocol, Some(Protocol::ADD));
Source

pub const ADD_ASSIGN: Protocol

The protocol for the addition assign operation.

§Examples
use rune::hash::IntoHash;
use rune::runtime::Protocol;

 let hash = Protocol::ADD_ASSIGN.into_hash();
let protocol = Protocol::from_hash(hash);
 assert_eq!(protocol, Some(Protocol::ADD_ASSIGN));
Source

pub const SUB: Protocol

The protocol for the subtraction operation.

§Examples
use rune::hash::IntoHash;
use rune::runtime::Protocol;

 let hash = Protocol::SUB.into_hash();
let protocol = Protocol::from_hash(hash);
 assert_eq!(protocol, Some(Protocol::SUB));
Source

pub const SUB_ASSIGN: Protocol

The protocol for the subtraction assign operation.

§Examples
use rune::hash::IntoHash;
use rune::runtime::Protocol;

 let hash = Protocol::SUB_ASSIGN.into_hash();
let protocol = Protocol::from_hash(hash);
 assert_eq!(protocol, Some(Protocol::SUB_ASSIGN));
Source

pub const MUL: Protocol

The protocol for the multiply operation.

§Examples
use rune::hash::IntoHash;
use rune::runtime::Protocol;

 let hash = Protocol::MUL.into_hash();
let protocol = Protocol::from_hash(hash);
 assert_eq!(protocol, Some(Protocol::MUL));
Source

pub const MUL_ASSIGN: Protocol

The protocol for the multiply assign operation.

§Examples
use rune::hash::IntoHash;
use rune::runtime::Protocol;

 let hash = Protocol::MUL_ASSIGN.into_hash();
let protocol = Protocol::from_hash(hash);
 assert_eq!(protocol, Some(Protocol::MUL_ASSIGN));
Source

pub const DIV: Protocol

The protocol for the division operation.

§Examples
use rune::hash::IntoHash;
use rune::runtime::Protocol;

 let hash = Protocol::DIV.into_hash();
let protocol = Protocol::from_hash(hash);
 assert_eq!(protocol, Some(Protocol::DIV));
Source

pub const DIV_ASSIGN: Protocol

The protocol for the division assign operation.

§Examples
use rune::hash::IntoHash;
use rune::runtime::Protocol;

 let hash = Protocol::DIV_ASSIGN.into_hash();
let protocol = Protocol::from_hash(hash);
 assert_eq!(protocol, Some(Protocol::DIV_ASSIGN));
Source

pub const REM: Protocol

The protocol for the remainder operation.

§Examples
use rune::hash::IntoHash;
use rune::runtime::Protocol;

 let hash = Protocol::REM.into_hash();
let protocol = Protocol::from_hash(hash);
 assert_eq!(protocol, Some(Protocol::REM));
Source

pub const REM_ASSIGN: Protocol

The protocol for the remainder assign operation.

§Examples
use rune::hash::IntoHash;
use rune::runtime::Protocol;

 let hash = Protocol::REM_ASSIGN.into_hash();
let protocol = Protocol::from_hash(hash);
 assert_eq!(protocol, Some(Protocol::REM_ASSIGN));
Source

pub const BIT_AND: Protocol

The protocol for the bitwise and operation.

§Examples
use rune::hash::IntoHash;
use rune::runtime::Protocol;

 let hash = Protocol::BIT_AND.into_hash();
let protocol = Protocol::from_hash(hash);
 assert_eq!(protocol, Some(Protocol::BIT_AND));
Source

pub const BIT_AND_ASSIGN: Protocol

The protocol for the bitwise and assign operation.

§Examples
use rune::hash::IntoHash;
use rune::runtime::Protocol;

 let hash = Protocol::BIT_AND_ASSIGN.into_hash();
let protocol = Protocol::from_hash(hash);
 assert_eq!(protocol, Some(Protocol::BIT_AND_ASSIGN));
Source

pub const BIT_XOR: Protocol

The protocol for the bitwise xor operation.

§Examples
use rune::hash::IntoHash;
use rune::runtime::Protocol;

 let hash = Protocol::BIT_XOR.into_hash();
let protocol = Protocol::from_hash(hash);
 assert_eq!(protocol, Some(Protocol::BIT_XOR));
Source

pub const BIT_XOR_ASSIGN: Protocol

The protocol for the bitwise xor assign operation.

§Examples
use rune::hash::IntoHash;
use rune::runtime::Protocol;

 let hash = Protocol::BIT_XOR_ASSIGN.into_hash();
let protocol = Protocol::from_hash(hash);
 assert_eq!(protocol, Some(Protocol::BIT_XOR_ASSIGN));
Source

pub const BIT_OR: Protocol

The protocol for the bitwise or operation.

§Examples
use rune::hash::IntoHash;
use rune::runtime::Protocol;

 let hash = Protocol::BIT_OR.into_hash();
let protocol = Protocol::from_hash(hash);
 assert_eq!(protocol, Some(Protocol::BIT_OR));
Source

pub const BIT_OR_ASSIGN: Protocol

The protocol for the bitwise xor assign operation.

§Examples
use rune::hash::IntoHash;
use rune::runtime::Protocol;

 let hash = Protocol::BIT_OR_ASSIGN.into_hash();
let protocol = Protocol::from_hash(hash);
 assert_eq!(protocol, Some(Protocol::BIT_OR_ASSIGN));
Source

pub const SHL: Protocol

The protocol for the bitwise shift left operation.

§Examples
use rune::hash::IntoHash;
use rune::runtime::Protocol;

 let hash = Protocol::SHL.into_hash();
let protocol = Protocol::from_hash(hash);
 assert_eq!(protocol, Some(Protocol::SHL));
Source

pub const SHL_ASSIGN: Protocol

The protocol for the bitwise shift left assign operation.

§Examples
use rune::hash::IntoHash;
use rune::runtime::Protocol;

 let hash = Protocol::SHL_ASSIGN.into_hash();
let protocol = Protocol::from_hash(hash);
 assert_eq!(protocol, Some(Protocol::SHL_ASSIGN));
Source

pub const SHR: Protocol

The protocol for the bitwise shift right operation.

§Examples
use rune::hash::IntoHash;
use rune::runtime::Protocol;

 let hash = Protocol::SHR.into_hash();
let protocol = Protocol::from_hash(hash);
 assert_eq!(protocol, Some(Protocol::SHR));
Source

pub const SHR_ASSIGN: Protocol

The protocol for the bitwise shift right assign operation.

§Examples
use rune::hash::IntoHash;
use rune::runtime::Protocol;

 let hash = Protocol::SHR_ASSIGN.into_hash();
let protocol = Protocol::from_hash(hash);
 assert_eq!(protocol, Some(Protocol::SHR_ASSIGN));
Source

pub const DISPLAY_FMT: Protocol

Protocol function used by template strings.

§Examples
use rune::hash::IntoHash;
use rune::runtime::Protocol;

 let hash = Protocol::DISPLAY_FMT.into_hash();
let protocol = Protocol::from_hash(hash);
 assert_eq!(protocol, Some(Protocol::DISPLAY_FMT));
Source

pub const DEBUG_FMT: Protocol

Protocol function used by custom debug impls.

§Examples
use rune::hash::IntoHash;
use rune::runtime::Protocol;

 let hash = Protocol::DEBUG_FMT.into_hash();
let protocol = Protocol::from_hash(hash);
 assert_eq!(protocol, Some(Protocol::DEBUG_FMT));
Source

pub const INTO_ITER: Protocol

Function used to convert an argument into an iterator.

§Examples
use rune::hash::IntoHash;
use rune::runtime::Protocol;

 let hash = Protocol::INTO_ITER.into_hash();
let protocol = Protocol::from_hash(hash);
 assert_eq!(protocol, Some(Protocol::INTO_ITER));
Source

pub const NEXT: Protocol

The function to call to continue iteration.

§Examples
use rune::hash::IntoHash;
use rune::runtime::Protocol;

 let hash = Protocol::NEXT.into_hash();
let protocol = Protocol::from_hash(hash);
 assert_eq!(protocol, Some(Protocol::NEXT));
Source

pub const NTH: Protocol

The function to call to continue iteration at the nth element.

§Examples
use rune::hash::IntoHash;
use rune::runtime::Protocol;

 let hash = Protocol::NTH.into_hash();
let protocol = Protocol::from_hash(hash);
 assert_eq!(protocol, Some(Protocol::NTH));
Source

pub const NTH_BACK: Protocol

The function to call to continue iteration at the nth element form the back.

§Examples
use rune::hash::IntoHash;
use rune::runtime::Protocol;

 let hash = Protocol::NTH_BACK.into_hash();
let protocol = Protocol::from_hash(hash);
 assert_eq!(protocol, Some(Protocol::NTH_BACK));
Source

pub const SIZE_HINT: Protocol

Protocol used when getting the size hint of an iterator.

§Examples
use rune::hash::IntoHash;
use rune::runtime::Protocol;

 let hash = Protocol::SIZE_HINT.into_hash();
let protocol = Protocol::from_hash(hash);
 assert_eq!(protocol, Some(Protocol::SIZE_HINT));
Source

pub const LEN: Protocol

Protocol used when getting the exact length of an iterator.

§Examples
use rune::hash::IntoHash;
use rune::runtime::Protocol;

 let hash = Protocol::LEN.into_hash();
let protocol = Protocol::from_hash(hash);
 assert_eq!(protocol, Some(Protocol::LEN));
Source

pub const NEXT_BACK: Protocol

Protocol used when cloning a value.

§Examples
use rune::hash::IntoHash;
use rune::runtime::Protocol;

 let hash = Protocol::NEXT_BACK.into_hash();
let protocol = Protocol::from_hash(hash);
 assert_eq!(protocol, Some(Protocol::NEXT_BACK));
Source

pub const INTO_FUTURE: Protocol

Function used to convert an argument into a future.

Signature: fn(Value) -> Future.

§Examples
use rune::hash::IntoHash;
use rune::runtime::Protocol;

 let hash = Protocol::INTO_FUTURE.into_hash();
let protocol = Protocol::from_hash(hash);
 assert_eq!(protocol, Some(Protocol::INTO_FUTURE));
Source

pub const INTO_TYPE_NAME: Protocol

Coerce a value into a type name. This is stored as a constant.

§Examples
use rune::hash::IntoHash;
use rune::runtime::Protocol;

 let hash = Protocol::INTO_TYPE_NAME.into_hash();
let protocol = Protocol::from_hash(hash);
 assert_eq!(protocol, Some(Protocol::INTO_TYPE_NAME));
Source

pub const IS_VARIANT: Protocol

Function used to test if a value is a specific variant.

Signature: fn(self, Hash) -> bool.

§Examples
use rune::hash::IntoHash;
use rune::runtime::Protocol;

 let hash = Protocol::IS_VARIANT.into_hash();
let protocol = Protocol::from_hash(hash);
 assert_eq!(protocol, Some(Protocol::IS_VARIANT));
Source

pub const TRY: Protocol

Function used for the question mark operation.

Signature: fn(self) -> Result.

Note that it uses the Result like Try uses ControlFlow i.e., for Result::<T, E> it should return Result<T, Result<(), E>>

§Examples
use rune::hash::IntoHash;
use rune::runtime::Protocol;

 let hash = Protocol::TRY.into_hash();
let protocol = Protocol::from_hash(hash);
 assert_eq!(protocol, Some(Protocol::TRY));
Source

pub const HASH: Protocol

Protocol used when calculating a hash.

§Examples
use rune::hash::IntoHash;
use rune::runtime::Protocol;

 let hash = Protocol::HASH.into_hash();
let protocol = Protocol::from_hash(hash);
 assert_eq!(protocol, Some(Protocol::HASH));
Source

pub const CLONE: Protocol

Protocol used when cloning a value.

§Examples
use rune::hash::IntoHash;
use rune::runtime::Protocol;

 let hash = Protocol::CLONE.into_hash();
let protocol = Protocol::from_hash(hash);
 assert_eq!(protocol, Some(Protocol::CLONE));
Source

pub const fn from_hash(hash: Hash) -> Option<Self>

Look up protocol for the given hash.

§Examples
use rune::runtime::Protocol;

let hash = Protocol::GET.hash;
let protocol = Protocol::from_hash(hash).ok_or("missing protocol")?;
assert_eq!(protocol, Protocol::GET);

Trait Implementations§

Source§

impl Debug for Protocol

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl Display for Protocol

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl Hash for Protocol

Source§

fn hash<H>(&self, state: &mut H)
where H: Hasher,

Feeds this value into the given Hasher. Read more
1.3.0 · Source§

fn hash_slice<H>(data: &[Self], state: &mut H)
where H: Hasher, Self: Sized,

Feeds a slice of this type into the given Hasher. Read more
Source§

impl IntoHash for &Protocol

Source§

fn into_hash(self) -> Hash

Convert current type into a hash.
Source§

impl PartialEq for Protocol

Source§

fn eq(&self, other: &Self) -> bool

Tests for self and other values to be equal, and is used by ==.
1.0.0 · Source§

fn ne(&self, other: &Rhs) -> bool

Tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
Source§

impl Eq for Protocol

Source§

impl ToTypeHash for &Protocol

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> ToString for T
where T: Display + ?Sized,

Source§

fn to_string(&self) -> String

Converts the given value to a String. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
Source§

impl<T> TryToString for T
where T: Display,

Source§

fn try_to_string(&self) -> Result<String, Error>

Converts the given value to a String. Read more