cortexkit_usage_steps/cursor.rs
1use serde::{Deserialize, Serialize};
2
3/// An opaque feed position issued by the provider.
4///
5/// Cursors are ordered by the provider's commits, are stable across restarts
6/// and are never reused, but apps never parse them or compare their order:
7/// they only pass one back as a read's `after`. This type therefore has no
8/// ordering; equality only says two values are the same cursor string.
9#[derive(Clone, Debug, PartialEq, Eq, Hash, Serialize, Deserialize)]
10#[serde(transparent)]
11pub struct Cursor(String);
12
13impl Cursor {
14 /// Wraps a cursor string exactly as received.
15 pub fn new(cursor: impl Into<String>) -> Self {
16 Self(cursor.into())
17 }
18
19 /// The cursor string, to send back unchanged.
20 pub fn as_str(&self) -> &str {
21 &self.0
22 }
23}
24
25impl From<String> for Cursor {
26 fn from(cursor: String) -> Self {
27 Self(cursor)
28 }
29}
30
31impl From<&str> for Cursor {
32 fn from(cursor: &str) -> Self {
33 Self(cursor.to_owned())
34 }
35}