#[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: StringThe 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: boolKeep 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
impl Source
Sourcepub fn label(&self) -> String
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§
impl Eq for Source
impl StructuralPartialEq for Source
Auto Trait Implementations§
impl Freeze for Source
impl RefUnwindSafe for Source
impl Send for Source
impl Sync for Source
impl Unpin for Source
impl UnsafeUnpin for Source
impl UnwindSafe for Source
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more