diff --git a/native/yex/src/array.rs b/native/yex/src/array.rs index 1bc99a6..f013737 100644 --- a/native/yex/src/array.rs +++ b/native/yex/src/array.rs @@ -6,7 +6,7 @@ use yrs::*; use crate::atoms; use crate::{ - doc::DocResource, error::NifError, wrap::NifWrap, yinput::NifYInput, youtput::NifValue, NifAny, + doc::DocResource, error::NifError, wrap::NifWrap, yinput::NifYInput, youtput::NifYOut, NifAny, }; pub type ArrayRefResource = NifWrap; @@ -56,12 +56,12 @@ impl NifArray { } Ok(()) } - pub fn get(&self, index: u32) -> Result { + pub fn get(&self, index: u32) -> Result { if let Some(txn) = self.doc.current_transaction.borrow_mut().as_mut() { let doc = self.doc.clone(); self.reference .get(txn, index) - .map(|b| NifValue::from_native(b, doc.clone())) + .map(|b| NifYOut::from_native(b, doc.clone())) .ok_or(NifError { reason: atoms::error(), message: "can not get".into(), @@ -72,26 +72,26 @@ impl NifArray { let doc = self.doc.clone(); self.reference .get(&txn, index) - .map(|b| NifValue::from_native(b, doc.clone())) + .map(|b| NifYOut::from_native(b, doc.clone())) .ok_or(NifError { reason: atoms::error(), message: "can not get".into(), }) } } - pub fn to_list(&self) -> Vec { + pub fn to_list(&self) -> Vec { if let Some(txn) = self.doc.current_transaction.borrow_mut().as_mut() { let doc = self.doc.clone(); self.reference .iter(txn) - .map(|b| NifValue::from_native(b, doc.clone())) + .map(|b| NifYOut::from_native(b, doc.clone())) .collect() } else { let txn = self.doc.0.doc.transact(); let doc = self.doc.clone(); self.reference .iter(&txn) - .map(|b| NifValue::from_native(b, doc.clone())) + .map(|b| NifYOut::from_native(b, doc.clone())) .collect() } } diff --git a/native/yex/src/lib.rs b/native/yex/src/lib.rs index 6c291d1..ccd2f78 100644 --- a/native/yex/src/lib.rs +++ b/native/yex/src/lib.rs @@ -23,7 +23,7 @@ use subscription::SubscriptionResource; use text::NifText; use wrap::encode_binary_slice_to_term; use yinput::NifYInput; -use youtput::NifValue; +use youtput::NifYOut; scoped_thread_local!( pub static ENV: for<'a> Env<'a> @@ -184,7 +184,7 @@ fn array_length(array: NifArray) -> u32 { array.length() } #[rustler::nif] -fn array_get(array: NifArray, index: u32) -> Result { +fn array_get(array: NifArray, index: u32) -> Result { array.get(index) } #[rustler::nif] @@ -197,7 +197,7 @@ fn array_delete_range( ENV.set(&mut env.clone(), || array.delete_range(index, length)) } #[rustler::nif] -fn array_to_list(array: NifArray) -> Vec { +fn array_to_list(array: NifArray) -> Vec { array.to_list() } #[rustler::nif] @@ -214,7 +214,7 @@ fn map_size(map: NifMap) -> u32 { map.size() } #[rustler::nif] -fn map_get(map: NifMap, key: &str) -> Result { +fn map_get(map: NifMap, key: &str) -> Result { map.get(key) } #[rustler::nif] @@ -222,7 +222,7 @@ fn map_delete(env: Env<'_>, map: NifMap, key: &str) -> Result<(), NifError> { ENV.set(&mut env.clone(), || map.delete(key)) } #[rustler::nif] -fn map_to_map(map: NifMap) -> HashMap { +fn map_to_map(map: NifMap) -> HashMap { map.to_map() } #[rustler::nif] diff --git a/native/yex/src/map.rs b/native/yex/src/map.rs index 48e9a76..610977d 100644 --- a/native/yex/src/map.rs +++ b/native/yex/src/map.rs @@ -1,6 +1,6 @@ use crate::atoms; use crate::{ - doc::DocResource, error::NifError, wrap::NifWrap, yinput::NifYInput, youtput::NifValue, NifAny, + doc::DocResource, error::NifError, wrap::NifWrap, yinput::NifYInput, youtput::NifYOut, NifAny, }; use rustler::{NifStruct, ResourceArc}; use std::{collections::HashMap, ops::Deref}; @@ -54,12 +54,12 @@ impl NifMap { } Ok(()) } - pub fn get(&self, key: &str) -> Result { + pub fn get(&self, key: &str) -> Result { if let Some(txn) = self.doc.current_transaction.borrow_mut().as_mut() { let doc = self.doc.clone(); self.reference .get(txn, key) - .map(|b| NifValue::from_native(b, doc.clone())) + .map(|b| NifYOut::from_native(b, doc.clone())) .ok_or(NifError { reason: atoms::error(), message: "can not get".into(), @@ -70,7 +70,7 @@ impl NifMap { let doc = self.doc.clone(); self.reference .get(&txn, key) - .map(|b| NifValue::from_native(b, doc.clone())) + .map(|b| NifYOut::from_native(b, doc.clone())) .ok_or(NifError { reason: atoms::error(), message: "can not get".into(), @@ -78,19 +78,19 @@ impl NifMap { } } - pub fn to_map(&self) -> HashMap { + pub fn to_map(&self) -> HashMap { if let Some(txn) = self.doc.current_transaction.borrow_mut().as_mut() { let doc = self.doc.clone(); self.reference .iter(txn) - .map(|(key, value)| (key.into(), NifValue::from_native(value, doc.clone()))) + .map(|(key, value)| (key.into(), NifYOut::from_native(value, doc.clone()))) .collect() } else { let txn = self.doc.0.doc.transact(); let doc = self.doc.clone(); self.reference .iter(&txn) - .map(|(key, value)| (key.into(), NifValue::from_native(value, doc.clone()))) + .map(|(key, value)| (key.into(), NifYOut::from_native(value, doc.clone()))) .collect() } } diff --git a/native/yex/src/youtput.rs b/native/yex/src/youtput.rs index d8a6819..62a6073 100644 --- a/native/yex/src/youtput.rs +++ b/native/yex/src/youtput.rs @@ -3,10 +3,9 @@ use crate::{ NifXmlElement, NifXmlFragment, NifXmlText, }; use rustler::{NifUntaggedEnum, ResourceArc}; -use yrs::Value; #[derive(NifUntaggedEnum)] -pub enum NifValue { +pub enum NifYOut { Any(NifAny), YText(NifText), YArray(NifArray), @@ -19,18 +18,18 @@ pub enum NifValue { UndefinedRef(NifUndefinedRef), } -impl NifValue { - pub fn from_native(v: Value, doc: ResourceArc) -> Self { +impl NifYOut { + pub fn from_native(v: yrs::Out, doc: ResourceArc) -> Self { match v { - yrs::Value::Any(any) => NifValue::Any(any.into()), - yrs::Value::YText(text) => NifValue::YText(NifText::new(doc, text)), - yrs::Value::YArray(array) => NifValue::YArray(NifArray::new(doc, array)), - yrs::Value::YMap(map) => NifValue::YMap(NifMap::new(doc, map)), - yrs::Value::YXmlElement(_) => NifValue::YXmlElement(NifXmlElement { doc }), - yrs::Value::YXmlFragment(_) => NifValue::YXmlFragment(NifXmlFragment {}), - yrs::Value::YXmlText(_) => NifValue::YXmlText(NifXmlText { doc }), - yrs::Value::YDoc(doc) => NifValue::YDoc(NifDoc::from_native(doc)), - yrs::Value::UndefinedRef(_) => NifValue::UndefinedRef(NifUndefinedRef { doc }), + yrs::Out::Any(any) => NifYOut::Any(any.into()), + yrs::Out::YText(text) => NifYOut::YText(NifText::new(doc, text)), + yrs::Out::YArray(array) => NifYOut::YArray(NifArray::new(doc, array)), + yrs::Out::YMap(map) => NifYOut::YMap(NifMap::new(doc, map)), + yrs::Out::YXmlElement(_) => NifYOut::YXmlElement(NifXmlElement { doc }), + yrs::Out::YXmlFragment(_) => NifYOut::YXmlFragment(NifXmlFragment {}), + yrs::Out::YXmlText(_) => NifYOut::YXmlText(NifXmlText { doc }), + yrs::Out::YDoc(doc) => NifYOut::YDoc(NifDoc::from_native(doc)), + yrs::Out::UndefinedRef(_) => NifYOut::UndefinedRef(NifUndefinedRef { doc }), } } }