Struct cdx::trans::TransMaker
source · [−]pub struct TransMaker {}
Expand description
Makes a Trans
Implementations
Add a new trans. If a Trans already exists by that name, replace it.
Add a new alias. If an alias already exists by that name, replace it.
Create a Trans from a trans spec and a pattern
make a dyn Trans from a named trans and a pattern
Examples found in repository
src/trans.rs (line 377)
356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379
pub fn make2(trans: &str, pattern: &str) -> Result<Transform> {
let mut spec = trans.to_string();
if !pattern.is_empty() {
spec.push(',');
spec.push_str(pattern);
}
let mut conf = TransSettings::default();
let mut kind = "";
if !trans.is_empty() {
for x in trans.split('.') {
if x.eq_ignore_ascii_case("utf8") {
conf.utf8 = true;
} else {
kind = x;
}
}
kind = Self::resolve_alias(kind);
}
Ok(Transform {
spec,
conf,
trans: Self::make_box(kind, &conf, pattern)?,
})
}
Create a trans from a full spec, i.e. “Trans,Pattern”
Examples found in repository
src/trans.rs (line 158)
≺ ≻
157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192
fn clone(&self) -> Self {
TransMaker::make(&self.spec).unwrap()
}
}
impl Transform {
fn trans(&mut self, src: &[u8], cont: &TextLine, dst: &mut Vec<u8>) -> Result<()> {
self.trans.trans(src, cont, dst)
}
fn lookup(&mut self, fieldnames: &[&str]) -> Result<()> {
self.trans.lookup(fieldnames)
}
}
#[derive(Default, Clone, Debug)]
/// a chain of transforms
pub struct TransList {
v: Vec<Transform>,
tmp1: Vec<u8>,
tmp2: Vec<u8>,
}
impl TransList {
/// new
pub fn new(spec: &str) -> Result<Self> {
let mut s = Self::default();
for x in spec.split('+') {
s.push(x)?;
}
Ok(s)
}
/// add new trans
pub fn push(&mut self, spec: &str) -> Result<()> {
self.v.push(TransMaker::make(spec)?);
Ok(())
}
Trait Implementations
Returns the “default value” for a type. Read more
Auto Trait Implementations
impl RefUnwindSafe for TransMaker
impl Send for TransMaker
impl Sync for TransMaker
impl Unpin for TransMaker
impl UnwindSafe for TransMaker
Blanket Implementations
Mutably borrows from an owned value. Read more
Attaches the provided Subscriber
to this type, returning a
WithDispatch
wrapper. Read more
Attaches the current default Subscriber
to this type, returning a
WithDispatch
wrapper. Read more