Skip to main content

Record

Struct Record 

Source
pub struct Record {
    pub envelope: Envelope,
    pub change: Change,
}
Expand description

One line of the log: its envelope and its change.

Fields§

§envelope: Envelope§change: Change

Implementations§

Source§

impl Record

Source

pub fn other(&self) -> Option<&'static str>

The field of this record whose value this build read as other: by, scope, reason, the kind or the to of a message, or a session URI (session, or the from of a message). None when the build knows each value. A record with such a value counts as a skipped record: the build writes no checkpoint past it (01M3XM2C18TT8VSKGD77YPZG53).

use riff_core::record::{Change, Line};

let read = |line: &str| match Line::parse(line).unwrap() {
    Line::Record(record) => record,
    Line::Unknown { .. } => panic!("a known kind"),
};
let known = r#"{"position":2,"written_at_ms":1,"by":{"person":"ann"},"command":"pause","change":{"pause_set":{"scope":"riff","state":"paused"}}}"#;
assert_eq!(read(known).other(), None);
assert_eq!(read(known).change.kind(), "pause_set");
assert!(Change::KINDS.contains(&"pause_set"));
// The values of a later build.
assert_eq!(read(&known.replace(r#""riff""#, r#"{"wave":"17"}"#)).other(), Some("scope"));
assert_eq!(read(&known.replace(r#""riff""#, r#""host""#)).other(), Some("scope"));
assert_eq!(read(&known.replace("person", "robot")).other(), Some("by"));
// The state of a pause has no `other`: the line does not read.
assert!(Line::parse(&known.replace(r#""paused""#, r#""slow""#)).is_err());

// A message of a later build: a kind, and a field of a selector.
let post = r#"{"position":3,"written_at_ms":1,"change":{"posted":{"thread":"acme/app","message":{"seq":1,"from":"riff://ann@heron/acme/app?session=s1","to":[{"user":"bob"}],"body":"hi","at_ms":1,"kind":"note"}}}}"#;
assert_eq!(read(post).other(), None);
assert_eq!(read(&post.replace("note", "poll")).other(), Some("kind"));
assert_eq!(read(&post.replace(r#"{"user":"bob"}"#, r#"{"user":"bob","wave":"17"}"#)).other(), Some("to"));
assert_eq!(read(&post.replace(r#"{"user":"bob"}"#, r#""all""#)).other(), Some("to"));
// A session URI with a query part of a later build.
assert_eq!(read(&post.replace("session=s1", "session=s1&wave=17")).other(), Some("from"));
Source§

impl Record

Source

pub fn of_repository(&self, repo: &ThreadName) -> bool

True when this record is a record of the repository thread repo for an audit (01M3ZWRC11R5M9V1KTF05P240W): a post, a membership, a lead, a claim or a release in that thread; a direct message from a session in that repository; the start or the end of a session in that repository; and a pause of the riff or of that repository. Each other record is not.

use riff_core::record::{Change, Claimed, Envelope, Line, PauseSet, Record, Scope};
use riff_core::wire::RiffState;

let repo = "acme/app".parse()?;
let envelope = Envelope { position: 1, written_at_ms: 1, by: None, command: None, call: None };
let record = |change| Record { envelope: envelope.clone(), change };
let claim = |thread: &str| record(Change::Claimed(Claimed {
    session: "riff://ann@heron/acme/app?session=s1".parse().unwrap(),
    thread: thread.parse().unwrap(),
    item: "issue-7".into(),
}));
assert!(claim("acme/app").of_repository(&repo));
assert!(!claim("acme/web").of_repository(&repo));

let pause = |scope| record(Change::PauseSet(PauseSet { scope, state: RiffState::Paused }));
assert!(pause(Scope::Riff).of_repository(&repo));
assert!(pause(Scope::Repository(repo.clone())).of_repository(&repo));
assert!(!pause(Scope::Repository("acme/web".parse()?)).of_repository(&repo));

// A record of the people is not a record of a repository.
let invited = r#"{"position":7,"written_at_ms":1,"change":{"member_invited":{"email":"ann@acme.io"}}}"#;
let Line::Record(invited) = Line::parse(invited)? else { panic!("a known kind") };
assert!(!invited.of_repository(&repo));
Source

pub fn for_audit(self) -> Record

This record for an audit: a post has only its mark (Posted::for_audit). Each other record stays as it is.

Trait Implementations§

Source§

impl Clone for Record

Source§

fn clone(&self) -> Record

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 Record

Source§

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

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

impl<'de> Deserialize<'de> for Record

Source§

fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>
where __D: Deserializer<'de>,

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

impl JsonSchema for Record

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 Record

Source§

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

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 Eq for Record

Source§

impl StructuralPartialEq for Record

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> 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>,