Skip to main content

Source

Enum Source 

Source
#[non_exhaustive]
pub enum Source { Index(String), Prefix { prefix: String, keep: bool, }, File(String), }
Expand description

Where a set of item names comes from.

use kevy_cli::backfill_keys::Source;
// `--from-index mail:by-date --from-prefix mail: --from-file archive.txt`
let sources = [
    Source::Index("mail:by-date".into()),
    Source::Prefix { prefix: "mail:".into(), keep: false },
    Source::File("archive.txt".into()),
];
let labels: Vec<String> = sources.iter().map(Source::label).collect();
assert_eq!(labels, ["index mail:by-date", "prefix mail:", "file archive.txt"]);

Variants (Non-exhaustive)§

This enum is marked as non-exhaustive
Non-exhaustive enums could have additional variants added in future. Therefore, when matching against variants of non-exhaustive enums, an extra wildcard arm must be added to account for any future variants.
§

Index(String)

The members of a set, sorted set, or list key.

use kevy_cli::backfill_keys::{Source, collect};
let mut client = kevy_resp_client::RespClient::connect("127.0.0.1", port)?;
client.request_borrowed(&[b"SADD", b"tags:rust", b"a", b"b"])?;
let u = collect(&mut client, &[Source::Index("tags:rust".into())])?;
assert_eq!(u.names.len(), 2);
§

Prefix

Every key in the keyspace under a prefix.

use kevy_cli::backfill_keys::{Source, collect};
let mut client = kevy_resp_client::RespClient::connect("127.0.0.1", port)?;
client.request_borrowed(&[b"SET", b"user:7", b"x"])?;
let source = Source::Prefix { prefix: "user:".into(), keep: false };
assert_eq!(collect(&mut client, &[source])?.names, vec![b"7".to_vec()]);

Fields

§prefix: String

The prefix to scan.

use kevy_cli::backfill_keys::Source;
let s = Source::Prefix { prefix: "order:".into(), keep: false };
assert_eq!(s.label(), "prefix order:");
§keep: bool

Keep the whole key rather than stripping the prefix.

Stripping is the default because the names then line up with the members of an index: mail:123 under mail: becomes 123, which is what a sorted set of ids holds. Keeping the prefix is right when the key is the name.

use kevy_cli::backfill_keys::{Source, collect};
let mut client = kevy_resp_client::RespClient::connect("127.0.0.1", port)?;
client.request_borrowed(&[b"SET", b"mail:123", b"x"])?;
let stripped = Source::Prefix { prefix: "mail:".into(), keep: false };
let whole = Source::Prefix { prefix: "mail:".into(), keep: true };
assert_eq!(collect(&mut client, &[stripped])?.names, vec![b"123".to_vec()]);
assert_eq!(collect(&mut client, &[whole])?.names, vec![b"mail:123".to_vec()]);
§

File(String)

One name per line, from a file (an archive listing, an export).

use kevy_cli::backfill_keys::{Source, collect};
let mut client = kevy_resp_client::RespClient::connect("127.0.0.1", port)?;
let dir = kevy_tmpdir::TmpDir::new("backfill-file");
let listing = dir.path().join("archive.txt");
std::fs::write(&listing, "41\n\n42\n")?; // blank lines are skipped
let source = Source::File(listing.to_string_lossy().into_owned());
let u = collect(&mut client, &[source])?;
assert_eq!(u.names, vec![b"41".to_vec(), b"42".to_vec()]);

Implementations§

Source§

impl Source

Source

pub fn label(&self) -> String

How this source prints in the report.

use kevy_cli::backfill_keys::Source;
assert_eq!(Source::Index("by-date".into()).label(), "index by-date");
let whole = Source::Prefix { prefix: "mail:".into(), keep: true };
assert_eq!(whole.label(), "prefix mail: (whole keys)");
assert_eq!(Source::File("ids.txt".into()).label(), "file ids.txt");

Trait Implementations§

Source§

impl Clone for Source

Source§

fn clone(&self) -> Self

Returns a duplicate of the value. Read more
1.0.0 (const: unstable) · Source§

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

Performs copy-assignment from source. Read more
Source§

impl Debug for Source

Source§

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

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

impl Eq for Source

Source§

impl Hash for Source

Source§

fn hash<__H: Hasher>(&self, state: &mut __H)

Feeds this value into the given Hasher. Read more
1.3.0 · Source§

fn hash_slice<H>(data: &[Self], state: &mut H)
where H: Hasher, Self: Sized,

Feeds a slice of this type into the given Hasher. Read more
Source§

impl PartialEq for Source

Source§

fn eq(&self, other: &Self) -> bool

Equality operator ==. Read more
1.0.0 (const: unstable) · Source§

fn ne(&self, other: &Rhs) -> bool

Inequality operator !=. Read more
Source§

impl StructuralPartialEq for Source

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 = !

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, !>

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.