Pre: introduce FromRc to convert between refcounted types.
This commit is contained in:
parent
4a42d2ca2c
commit
9292867dc9
1 changed files with 39 additions and 2 deletions
|
@ -8,9 +8,15 @@
|
||||||
// CONDITIONS OF ANY KIND, either express or implied. See the License for the
|
// CONDITIONS OF ANY KIND, either express or implied. See the License for the
|
||||||
// specific language governing permissions and limitations under the License.
|
// specific language governing permissions and limitations under the License.
|
||||||
|
|
||||||
use std::fmt;
|
use ::std::rc::{
|
||||||
use std::rc::Rc;
|
Rc,
|
||||||
|
};
|
||||||
|
|
||||||
|
use ::std::sync::{
|
||||||
|
Arc,
|
||||||
|
};
|
||||||
|
|
||||||
|
use std::fmt;
|
||||||
use ::enum_set::EnumSet;
|
use ::enum_set::EnumSet;
|
||||||
|
|
||||||
use ::ordered_float::OrderedFloat;
|
use ::ordered_float::OrderedFloat;
|
||||||
|
@ -35,6 +41,37 @@ use ::edn::{
|
||||||
|
|
||||||
use values;
|
use values;
|
||||||
|
|
||||||
|
pub trait FromRc<T> {
|
||||||
|
fn from_rc(val: Rc<T>) -> Self;
|
||||||
|
fn from_arc(val: Arc<T>) -> Self;
|
||||||
|
}
|
||||||
|
|
||||||
|
impl<T> FromRc<T> for Rc<T> where T: Sized + Clone {
|
||||||
|
fn from_rc(val: Rc<T>) -> Self {
|
||||||
|
val.clone()
|
||||||
|
}
|
||||||
|
|
||||||
|
fn from_arc(val: Arc<T>) -> Self {
|
||||||
|
match ::std::sync::Arc::<T>::try_unwrap(val) {
|
||||||
|
Ok(v) => Self::new(v),
|
||||||
|
Err(r) => Self::new((*r.as_ref()).clone()),
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
impl<T> FromRc<T> for Arc<T> where T: Sized + Clone {
|
||||||
|
fn from_rc(val: Rc<T>) -> Self {
|
||||||
|
match ::std::rc::Rc::<T>::try_unwrap(val) {
|
||||||
|
Ok(v) => Self::new(v),
|
||||||
|
Err(r) => Self::new((*r.as_ref()).clone()),
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
fn from_arc(val: Arc<T>) -> Self {
|
||||||
|
val.clone()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
/// Represents one entid in the entid space.
|
/// Represents one entid in the entid space.
|
||||||
///
|
///
|
||||||
/// Per https://www.sqlite.org/datatype3.html (see also http://stackoverflow.com/a/8499544), SQLite
|
/// Per https://www.sqlite.org/datatype3.html (see also http://stackoverflow.com/a/8499544), SQLite
|
||||||
|
|
Loading…
Reference in a new issue