Skip to main content

Narrative

Struct Narrative 

Source
pub struct Narrative {
    pub id: NarrativeId,
    pub title: String,
    pub events: Vec<Event>,
    pub metadata: NarrativeMetadata,
    pub tags: Vec<String>,
}
Expand description

A collection of related events forming a coherent story.

Narratives are the primary container for organizing events into meaningful stories with geographic and temporal structure.

§Examples

use spatial_narrative::core::{Narrative, Event, Location, Timestamp};

let mut narrative = Narrative::builder()
    .title("Hurricane Timeline")
    .description("Tracking the hurricane's path")
    .category("disaster")
    .build();

narrative.add_event(Event::builder()
    .location(Location::new(25.0, -80.0))
    .timestamp(Timestamp::now())
    .text("Hurricane makes landfall")
    .tag("landfall")
    .build());

Fields§

§id: NarrativeId

Unique identifier.

§title: String

Title of the narrative.

§events: Vec<Event>

Events in this narrative.

§metadata: NarrativeMetadata

Narrative metadata.

§tags: Vec<String>

Categorical tags for the narrative.

Implementations§

Source§

impl Narrative

Source

pub fn new(title: impl Into<String>) -> Self

Creates a new narrative with the given title.

Source

pub fn builder() -> NarrativeBuilder

Creates a builder for constructing a Narrative.

Source

pub fn events(&self) -> &[Event]

Returns the events in this narrative.

Source

pub fn events_mut(&mut self) -> &mut Vec<Event>

Returns a mutable reference to the events.

Source

pub fn len(&self) -> usize

Returns the number of events.

Source

pub fn is_empty(&self) -> bool

Returns true if the narrative has no events.

Source

pub fn add_event(&mut self, event: Event)

Adds an event to the narrative.

Source

pub fn remove_event(&mut self, id: &EventId) -> Option<Event>

Removes an event by ID.

Source

pub fn get_event(&self, id: &EventId) -> Option<&Event>

Finds an event by ID.

Source

pub fn get_event_mut(&mut self, id: &EventId) -> Option<&mut Event>

Finds an event by ID (mutable).

Source

pub fn events_chronological(&self) -> Vec<&Event>

Returns events sorted by timestamp.

Source

pub fn filter_spatial(&self, bounds: &GeoBounds) -> Vec<&Event>

Filters events by spatial bounds.

Source

pub fn filter_temporal(&self, range: &TimeRange) -> Vec<&Event>

Filters events by time range.

Source

pub fn filter_by_tag(&self, tag: &str) -> Vec<&Event>

Filters events by tag.

Source

pub fn bounds(&self) -> Option<GeoBounds>

Returns the geographic bounds of all events.

Source

pub fn time_range(&self) -> Option<TimeRange>

Returns the time range spanning all events.

Source

pub fn all_tags(&self) -> Vec<&str>

Returns all unique tags used by events in this narrative.

Source

pub fn add_tag(&mut self, tag: impl Into<String>)

Adds a tag to the narrative.

Source

pub fn filter<F>(&self, predicate: F) -> Narrative
where F: Fn(&Event) -> bool,

Creates a new narrative containing only events that match the predicate.

Source

pub fn merge(&mut self, other: Narrative)

Merges another narrative into this one.

Trait Implementations§

Source§

impl Clone for Narrative

Source§

fn clone(&self) -> Narrative

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 Narrative

Source§

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

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

impl Default for Narrative

Source§

fn default() -> Self

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

impl<'de> Deserialize<'de> for Narrative

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 Narrative

Source§

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

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 StructuralPartialEq for Narrative

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