Skip to main content

Kind

Enum Kind 

Source
pub enum Kind {
    Message,
    Status,
    Note,
    Riff,
    Other,
}
Expand description

The kind of a post. A post call sends message, status or note.

use riff_core::wire::Kind;

assert_eq!(serde_json::to_string(&Kind::Status).unwrap(), r#""status""#);
assert_eq!("status".parse::<Kind>(), Ok(Kind::Status));
assert_eq!(serde_json::to_string(&Kind::Note).unwrap(), r#""note""#);
assert_eq!("note".parse::<Kind>(), Ok(Kind::Note));
assert!("other".parse::<Kind>().is_err());
assert!(Kind::Note.needs_body() && !Kind::Status.needs_body());

Variants§

§

Message

A message to read.

§

Status

A status request. Each session that it wakes sets its status with status. It does not post a reply.

§

Note

A note: it informs and wakes no session. A session sees it at its next read (01M3JPMQE6S7YM4HPEVGXWK7ET).

§

Riff

A message that riff itself writes, as the person of the riff: the watch of a deploy, the daemon, the lines of riff release. It reads and wakes as a message. It never counts as the word of a person (Kind::by_riff). A session has no use for it, so a schema of a call does not list it.

§

Other

A kind that this build does not know. A reader shows the post as a message.

Implementations§

Source§

impl Kind

Source

pub fn is_message(&self) -> bool

Source

pub fn by_riff(&self) -> bool

True for the kind of a line that riff writes, not a person: Kind::Riff.

use riff_core::wire::Kind;

assert!(Kind::Riff.by_riff());
assert!(![Kind::Message, Kind::Status, Kind::Note, Kind::Other].iter().any(Kind::by_riff));
Source

pub fn needs_body(&self) -> bool

True when a post of this kind needs a body. Only a status request needs none.

Source

pub fn is_post(&self) -> bool

True for a kind that a post call can have. A kind of a later build reads as Kind::Other, and no post call can have it (01M3XSF90E9JYYTC13D9THY4WE).

use riff_core::wire::Kind;

let read = |json: &str| serde_json::from_str::<Kind>(json).unwrap();
assert_eq!(read(r#""note""#), Kind::Note);
// The kind of a line of riff has a name in JSON, and none for a person.
assert_eq!(read(r#""riff""#), Kind::Riff);
assert_eq!(serde_json::to_string(&Kind::Riff).unwrap(), r#""riff""#);
assert!("riff".parse::<Kind>().is_err());
// A kind of a later build can have each form of JSON.
for later in [r#""poll""#, r#"{"poll":"wave"}"#, "7", "null"] {
    assert_eq!(read(later), Kind::Other, "{later}");
}
assert!(Kind::Note.is_post() && Kind::Riff.is_post() && !Kind::Other.is_post());
assert_eq!(serde_json::to_string(&Kind::Other).unwrap(), r#""other""#);

// The schema of a call has only the kinds of a `post` call.
let schema = serde_json::to_value(schemars::schema_for!(Kind)).unwrap();
let kinds: Vec<&str> = schema["oneOf"]
    .as_array()
    .unwrap()
    .iter()
    .map(|kind| kind["const"].as_str().unwrap())
    .collect();
assert_eq!(kinds, ["message", "status", "note"]);

Trait Implementations§

Source§

impl Clone for Kind

Source§

fn clone(&self) -> Kind

Returns a duplicate of the value. Read more
1.0.0 · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl Debug for Kind

Source§

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

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

impl Default for Kind

Source§

fn default() -> Kind

Returns the “default value” for a type. Read more
Source§

impl<'de> Deserialize<'de> for Kind

The set of kinds can grow. A build reads each value that it does not know as Kind::Other: a text, and each other form of JSON (01M3XSF90E9JYYTC13D9THY4WE). The kind Kind::Riff has a name in JSON but not in FromStr: a person types no such kind.

Source§

fn deserialize<D: Deserializer<'de>>(deserializer: D) -> Result<Self, D::Error>

Deserialize this value from the given Serde deserializer. Read more
Source§

impl FromStr for Kind

Source§

type Err = String

The associated error which can be returned from parsing.
Source§

fn from_str(text: &str) -> Result<Self, Self::Err>

Parses a string s to return a value of this type. Read more
Source§

impl JsonSchema for Kind

Source§

fn schema_name() -> Cow<'static, str>

The name of the generated JSON Schema. Read more
Source§

fn schema_id() -> Cow<'static, str>

Returns a string that uniquely identifies the schema produced by this type. Read more
Source§

fn json_schema(generator: &mut SchemaGenerator) -> Schema

Generates a JSON Schema for this type. Read more
Source§

fn inline_schema() -> bool

Whether JSON Schemas generated for this type should be included directly in parent schemas, rather than being re-used where possible using the $ref keyword. Read more
Source§

impl PartialEq for Kind

Source§

fn eq(&self, other: &Kind) -> 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 Serialize for Kind

Source§

fn serialize<__S>(&self, __serializer: __S) -> Result<__S::Ok, __S::Error>
where __S: Serializer,

Serialize this value into the given Serde serializer. Read more
Source§

impl Copy for Kind

Source§

impl Eq for Kind

Source§

impl StructuralPartialEq for Kind

Auto Trait Implementations§

§

impl Freeze for Kind

§

impl RefUnwindSafe for Kind

§

impl Send for Kind

§

impl Sync for Kind

§

impl Unpin for Kind

§

impl UnsafeUnpin for Kind

§

impl UnwindSafe for Kind

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> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> DynClone for T
where T: Clone,

Source§

fn __clone_box(&self, _: Private) -> *mut ()

§

impl<Q, K> Equivalent<K> for Q
where Q: Eq + ?Sized, K: Borrow<Q> + ?Sized,

§

fn equivalent(&self, key: &K) -> bool

Compare self to key and return true if they are equal.
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> Same for T

Source§

type Output = T

Should always be Self
Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. 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> DeserializeOwned for T
where T: for<'de> Deserialize<'de>,