Struct WatchEvent

Source
#[non_exhaustive]
pub struct WatchEvent { /* private fields */ }
Expand description

One normalized provider watch event.

Sequence numbers are interpreted within a provider generation; this type stores but does not validate monotonicity. Rename/move events can carry a previous URI, and any event can carry a stable identity. The struct is non-exhaustive so it can gain correlation fields compatibly.

§Examples

use ailloli_ui_fs::{FileUri, WatchEvent, WatchEventKind};
let event = WatchEvent::new(WatchEventKind::Created, FileUri::parse("file:///new")?, 1, 4);
assert_eq!((event.sequence(), event.generation()), (1, 4));

Implementations§

Source§

impl WatchEvent

Source

pub fn new( kind: WatchEventKind, uri: FileUri, sequence: u64, generation: u64, ) -> Self

Creates an event without previous URI or stable identity.

Zero and non-monotone sequence/generation values are accepted verbatim.

§Examples
use ailloli_ui_fs::{FileUri, WatchEvent, WatchEventKind};
let event = WatchEvent::new(WatchEventKind::Modified, FileUri::parse("file:///a")?, 0, 0);
assert_eq!(event.previous_uri(), None);
Source

pub fn with_previous_uri(self, previous_uri: FileUri) -> Self

Attaches the entry’s former URI.

The value is accepted for every event kind and replaces an earlier one.

§Examples
use ailloli_ui_fs::{FileUri, WatchEvent, WatchEventKind};
let event = WatchEvent::new(WatchEventKind::Renamed, FileUri::parse("file:///new")?, 1, 1)
    .with_previous_uri(FileUri::parse("file:///old")?);
assert_eq!(event.previous_uri().unwrap().path(), "/old");
Source

pub fn with_identity(self, identity: FileIdentity) -> Self

Attaches a provider-stable identity, replacing any previous identity.

§Examples
use ailloli_ui_fs::{FileIdentity, FileUri, WatchEvent, WatchEventKind};
let event = WatchEvent::new(WatchEventKind::Created, FileUri::parse("file:///a")?, 1, 1)
    .with_identity(FileIdentity::new("local", [1]));
assert_eq!(event.identity().unwrap().value(), &[1]);
Source

pub const fn kind(&self) -> WatchEventKind

Returns the normalized event category.

§Examples
use ailloli_ui_fs::{FileUri, WatchEvent, WatchEventKind};
let event = WatchEvent::new(WatchEventKind::Overflow, FileUri::parse("file:///")?, 1, 1);
assert_eq!(event.kind(), WatchEventKind::Overflow);
Source

pub const fn uri(&self) -> &FileUri

Borrows the entry’s current/event URI.

§Examples
use ailloli_ui_fs::{FileUri, WatchEvent, WatchEventKind};
let event = WatchEvent::new(WatchEventKind::Removed, FileUri::parse("file:///a")?, 1, 1);
assert_eq!(event.uri().path(), "/a");
Source

pub const fn previous_uri(&self) -> Option<&FileUri>

Borrows the former URI, or returns None when it was not supplied.

§Examples
use ailloli_ui_fs::{FileUri, WatchEvent, WatchEventKind};
let event = WatchEvent::new(WatchEventKind::Created, FileUri::parse("file:///a")?, 1, 1);
assert!(event.previous_uri().is_none());
Source

pub const fn sequence(&self) -> u64

Returns the provider sequence number within its generation.

§Examples
use ailloli_ui_fs::{FileUri, WatchEvent, WatchEventKind};
let event = WatchEvent::new(WatchEventKind::Created, FileUri::parse("file:///a")?, 7, 2);
assert_eq!(event.sequence(), 7);
Source

pub const fn generation(&self) -> u64

Returns the provider watch-generation identifier.

§Examples
use ailloli_ui_fs::{FileUri, WatchEvent, WatchEventKind};
let event = WatchEvent::new(WatchEventKind::Created, FileUri::parse("file:///a")?, 7, 2);
assert_eq!(event.generation(), 2);
Source

pub const fn identity(&self) -> Option<&FileIdentity>

Borrows the stable identity, or returns None when unavailable.

§Examples
use ailloli_ui_fs::{FileUri, WatchEvent, WatchEventKind};
let event = WatchEvent::new(WatchEventKind::Created, FileUri::parse("file:///a")?, 1, 1);
assert!(event.identity().is_none());

Trait Implementations§

Source§

impl Clone for WatchEvent

Source§

fn clone(&self) -> WatchEvent

Returns a copy 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 WatchEvent

Source§

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

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

impl<'de> Deserialize<'de> for WatchEvent

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 PartialEq for WatchEvent

Source§

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

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 WatchEvent

Source§

impl StructuralPartialEq for WatchEvent

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