Add retract_kw
This commit is contained in:
parent
9655c4b85d
commit
48ffa20d4c
1 changed files with 19 additions and 5 deletions
|
@ -259,11 +259,21 @@ impl<'a, 'c> InProgressBuilder<'a, 'c> {
|
||||||
pub fn add_kw<E, V>(&mut self, e: E, a: &NamespacedKeyword, v: V) -> Result<()>
|
pub fn add_kw<E, V>(&mut self, e: E, a: &NamespacedKeyword, v: V) -> Result<()>
|
||||||
where E: IntoThing<KnownEntidOr<TempIdHandle>>,
|
where E: IntoThing<KnownEntidOr<TempIdHandle>>,
|
||||||
V: IntoThing<TypedValueOr<TempIdHandle>> {
|
V: IntoThing<TypedValueOr<TempIdHandle>> {
|
||||||
|
let (attribute, value) = self.extract_kw_value(a, v.into_thing())?;
|
||||||
|
self.add(e, attribute, value)
|
||||||
|
}
|
||||||
|
|
||||||
|
pub fn retract_kw<E, V>(&mut self, e: E, a: &NamespacedKeyword, v: V) -> Result<()>
|
||||||
|
where E: IntoThing<KnownEntidOr<TempIdHandle>>,
|
||||||
|
V: IntoThing<TypedValueOr<TempIdHandle>> {
|
||||||
|
let (attribute, value) = self.extract_kw_value(a, v.into_thing())?;
|
||||||
|
self.retract(e, attribute, value)
|
||||||
|
}
|
||||||
|
|
||||||
|
fn extract_kw_value(&mut self, a: &NamespacedKeyword, v: TypedValueOr<TempIdHandle>) -> Result<(KnownEntid, TypedValueOr<TempIdHandle>)> {
|
||||||
let attribute: KnownEntid;
|
let attribute: KnownEntid;
|
||||||
let value: TypedValueOr<TempIdHandle>;
|
|
||||||
if let Some((attr, aa)) = self.in_progress.attribute_for_ident(a) {
|
if let Some((attr, aa)) = self.in_progress.attribute_for_ident(a) {
|
||||||
let vv = v.into_thing();
|
if let Either::Left(ref tv) = v {
|
||||||
if let Either::Left(ref tv) = vv {
|
|
||||||
let provided = tv.value_type();
|
let provided = tv.value_type();
|
||||||
let expected = attr.value_type;
|
let expected = attr.value_type;
|
||||||
if provided != expected {
|
if provided != expected {
|
||||||
|
@ -271,11 +281,10 @@ impl<'a, 'c> InProgressBuilder<'a, 'c> {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
attribute = aa;
|
attribute = aa;
|
||||||
value = vv;
|
|
||||||
} else {
|
} else {
|
||||||
bail!(ErrorKind::UnknownAttribute(a.to_string()));
|
bail!(ErrorKind::UnknownAttribute(a.to_string()));
|
||||||
}
|
}
|
||||||
self.add(e, attribute, value)
|
Ok((attribute, v))
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -285,6 +294,11 @@ impl<'a, 'c> EntityBuilder<InProgressBuilder<'a, 'c>> {
|
||||||
self.builder.add_kw(self.entity.clone(), a, v)
|
self.builder.add_kw(self.entity.clone(), a, v)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
pub fn retract_kw<V>(&mut self, a: &NamespacedKeyword, v: V) -> Result<()>
|
||||||
|
where V: IntoThing<TypedValueOr<TempIdHandle>> {
|
||||||
|
self.builder.retract_kw(self.entity.clone(), a, v)
|
||||||
|
}
|
||||||
|
|
||||||
/// Build the terms from this builder and transact them against the current
|
/// Build the terms from this builder and transact them against the current
|
||||||
/// `InProgress`. This method _always_ returns the `InProgress` -- failure doesn't
|
/// `InProgress`. This method _always_ returns the `InProgress` -- failure doesn't
|
||||||
/// imply an automatic rollback.
|
/// imply an automatic rollback.
|
||||||
|
|
Loading…
Reference in a new issue