Fixed the compilation errors caused by merging PR

 into the "experiment" branch.
This commit is contained in:
Jason Kankiewicz 2022-04-20 00:57:52 -06:00
parent 8005f31a95
commit aaa2f7489b
7 changed files with 27 additions and 39 deletions

View file

@ -40,13 +40,13 @@ impl AMdoc {
}
}
pub fn set_object<O: AsRef<am::ObjId>, P: Into<am::Prop>>(
pub fn put_object<O: AsRef<am::ObjId>, P: Into<am::Prop>>(
&mut self,
obj: O,
prop: P,
value: am::ObjType,
) -> Result<&AMobjId, am::AutomergeError> {
match self.body.set_object(obj, prop, value) {
match self.body.put_object(obj, prop, value) {
Ok(ex_id) => {
let obj_id = AMobjId::new(ex_id);
self.obj_ids.insert(obj_id.clone());

View file

@ -1,7 +1,7 @@
use automerge as am;
use hex;
use smol_str::SmolStr;
use std::{ffi::CStr, ffi::CString, os::raw::c_char};
use std::{borrow::Cow, ffi::CStr, ffi::CString, os::raw::c_char};
mod doc;
mod result;
@ -66,7 +66,7 @@ macro_rules! to_doc {
macro_rules! to_obj_id {
($handle:expr) => {{
match $handle.as_ref() {
Some(am_obj_id) => am_obj_id,
Some(obj_id) => obj_id,
None => &am::ROOT,
}
}};
@ -160,7 +160,7 @@ pub unsafe extern "C" fn AMgetActor<'a>(doc: *mut AMdoc) -> *mut AMresult<'a> {
pub unsafe extern "C" fn AMgetActorHex<'a>(doc: *mut AMdoc) -> *mut AMresult<'a> {
let doc = to_doc!(doc);
let hex_str = doc.get_actor().to_hex_string();
let value = am::Value::Scalar(am::ScalarValue::Str(SmolStr::new(hex_str)));
let value = am::Value::Scalar(Cow::Owned(am::ScalarValue::Str(SmolStr::new(hex_str))));
to_result(Ok(value))
}
@ -220,7 +220,7 @@ pub unsafe extern "C" fn AMsetActorHex<'a>(
doc.set_actor(vec.into());
Ok(())
}
Err(_) => Err(am::AutomergeError::Decoding),
Err(error) => Err(am::AutomergeError::HexDecode(error)),
})
}
@ -296,7 +296,7 @@ pub unsafe extern "C" fn AMresultValue<'a>(result: *mut AMresult<'a>, index: usi
AMresult::Scalars(vec, hosted_str) => {
if let Some(element) = vec.get(index) {
match element {
am::Value::Scalar(scalar) => match scalar {
am::Value::Scalar(scalar) => match scalar.as_ref() {
am::ScalarValue::Boolean(flag) => {
value = AMvalue::Boolean(*flag as i8);
}
@ -638,7 +638,7 @@ pub unsafe extern "C" fn AMlistGet<'a>(
index: usize,
) -> *mut AMresult<'a> {
let doc = to_doc!(doc);
to_result(doc.value(to_obj_id!(obj_id), index))
to_result(doc.get(to_obj_id!(obj_id), index))
}
/// \memberof AMdoc
@ -665,7 +665,7 @@ pub unsafe extern "C" fn AMmapGet<'a>(
key: *const c_char,
) -> *mut AMresult<'a> {
let doc = to_doc!(doc);
to_result(doc.value(to_obj_id!(obj_id), to_str(key)))
to_result(doc.get(to_obj_id!(obj_id), to_str(key)))
}
/// \memberof AMdoc

View file

@ -1,5 +1,6 @@
use automerge as am;
use std::ffi::CString;
use std::ops::Deref;
/// \struct AMobjId
/// \brief An object's unique identifier.
@ -18,6 +19,14 @@ impl AsRef<am::ObjId> for AMobjId {
}
}
impl Deref for AMobjId {
type Target = am::ObjId;
fn deref(&self) -> &Self::Target {
&self.0
}
}
/// \memberof AMvalue
/// \struct AMbyteSpan
/// \brief A contiguous sequence of bytes.
@ -180,8 +189,8 @@ impl<'a> From<Result<(), am::AutomergeError>> for AMresult<'a> {
}
}
impl<'a> From<Result<Option<(am::Value, am::ObjId)>, am::AutomergeError>> for AMresult<'a> {
fn from(maybe: Result<Option<(am::Value, am::ObjId)>, am::AutomergeError>) -> Self {
impl<'a> From<Result<Option<(am::Value<'static>, am::ObjId)>, am::AutomergeError>> for AMresult<'a> {
fn from(maybe: Result<Option<(am::Value<'static>, am::ObjId)>, am::AutomergeError>) -> Self {
match maybe {
// \todo Ensure that it's alright to ignore the `am::ObjId` value.
Ok(Some((value, _))) => AMresult::Scalars(vec![value], None),
@ -191,8 +200,8 @@ impl<'a> From<Result<Option<(am::Value, am::ObjId)>, am::AutomergeError>> for AM
}
}
impl<'a> From<Result<am::Value, am::AutomergeError>> for AMresult<'a> {
fn from(maybe: Result<am::Value, am::AutomergeError>) -> Self {
impl<'a> From<Result<am::Value<'static>, am::AutomergeError>> for AMresult<'a> {
fn from(maybe: Result<am::Value<'static>, am::AutomergeError>) -> Self {
match maybe {
Ok(value) => AMresult::Scalars(vec![value], None),
Err(e) => AMresult::Error(CString::new(e.to_string()).unwrap()),

View file

@ -1,21 +1,4 @@
use crate::{AMobjId, AMresult};
use automerge as am;
use std::ops::Deref;
impl Deref for AMobjId {
type Target = am::ObjId;
fn deref(&self) -> &Self::Target {
&self.0
}
}
#[allow(clippy::not_unsafe_ptr_arg_deref)]
impl From<*const AMobjId> for AMobjId {
fn from(obj_id: *const AMobjId) -> Self {
unsafe { obj_id.as_ref().unwrap_or(AMobjId(am::ROOT)) }
}
}
use crate::AMresult;
impl<'a> From<AMresult<'a>> for *mut AMresult<'a> {
fn from(b: AMresult<'a>) -> Self {

View file

@ -50,7 +50,7 @@ static int teardown(void** state) {
static void test_AMputActor(void **state) {
TestState* test_state = *state;
GroupState* group_state = test_state->group_state;
AMresult* res = AMputActor(
AMresult* res = AMsetActor(
group_state->doc,
test_state->actor_id_bytes,
test_state->actor_id_size
@ -77,7 +77,7 @@ static void test_AMputActor(void **state) {
static void test_AMputActorHex(void **state) {
TestState* test_state = *state;
GroupState* group_state = test_state->group_state;
AMresult* res = AMputActorHex(
AMresult* res = AMsetActorHex(
group_state->doc,
test_state->actor_id_str
);

View file

@ -25,6 +25,8 @@ pub enum AutomergeError {
InvalidHash(ChangeHash),
#[error("general failure")]
Fail,
#[error(transparent)]
HexDecode(#[from] hex::FromHexError),
}
#[cfg(feature = "wasm")]

View file

@ -686,12 +686,6 @@ impl From<bool> for ScalarValue {
}
}
impl From<Vec<u8>> for ScalarValue {
fn from(b: Vec<u8>) -> Self {
ScalarValue::Bytes(b)
}
}
impl From<()> for ScalarValue {
fn from(_: ()) -> Self {
ScalarValue::Null