Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix deprecated warning #8

Merged
merged 1 commit into from
Jul 20, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 7 additions & 7 deletions native/yex/src/array.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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<ArrayRef>;
Expand Down Expand Up @@ -56,12 +56,12 @@ impl NifArray {
}
Ok(())
}
pub fn get(&self, index: u32) -> Result<NifValue, NifError> {
pub fn get(&self, index: u32) -> Result<NifYOut, NifError> {
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(),
Expand All @@ -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<NifValue> {
pub fn to_list(&self) -> Vec<NifYOut> {
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()
}
}
Expand Down
10 changes: 5 additions & 5 deletions native/yex/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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>
Expand Down Expand Up @@ -184,7 +184,7 @@ fn array_length(array: NifArray) -> u32 {
array.length()
}
#[rustler::nif]
fn array_get(array: NifArray, index: u32) -> Result<NifValue, NifError> {
fn array_get(array: NifArray, index: u32) -> Result<NifYOut, NifError> {
array.get(index)
}
#[rustler::nif]
Expand All @@ -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<NifValue> {
fn array_to_list(array: NifArray) -> Vec<NifYOut> {
array.to_list()
}
#[rustler::nif]
Expand All @@ -214,15 +214,15 @@ fn map_size(map: NifMap) -> u32 {
map.size()
}
#[rustler::nif]
fn map_get(map: NifMap, key: &str) -> Result<NifValue, NifError> {
fn map_get(map: NifMap, key: &str) -> Result<NifYOut, NifError> {
map.get(key)
}
#[rustler::nif]
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<String, NifValue> {
fn map_to_map(map: NifMap) -> HashMap<String, NifYOut> {
map.to_map()
}
#[rustler::nif]
Expand Down
14 changes: 7 additions & 7 deletions native/yex/src/map.rs
Original file line number Diff line number Diff line change
@@ -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};
Expand Down Expand Up @@ -54,12 +54,12 @@ impl NifMap {
}
Ok(())
}
pub fn get(&self, key: &str) -> Result<NifValue, NifError> {
pub fn get(&self, key: &str) -> Result<NifYOut, NifError> {
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(),
Expand All @@ -70,27 +70,27 @@ 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(),
})
}
}

pub fn to_map(&self) -> HashMap<String, NifValue> {
pub fn to_map(&self) -> HashMap<String, NifYOut> {
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()
}
}
Expand Down
25 changes: 12 additions & 13 deletions native/yex/src/youtput.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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),
Expand All @@ -19,18 +18,18 @@ pub enum NifValue {
UndefinedRef(NifUndefinedRef),
}

impl NifValue {
pub fn from_native(v: Value, doc: ResourceArc<DocResource>) -> Self {
impl NifYOut {
pub fn from_native(v: yrs::Out, doc: ResourceArc<DocResource>) -> 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 }),
}
}
}
Loading