mirror of
https://github.com/hannobraun/Fornjot
synced 2025-05-06 19:08:28 +00:00
Move Handle
to dedicated module
This commit is contained in:
parent
1527528c53
commit
f57664c0c9
83
experiments/2024-12-09/src/operation/handle.rs
Normal file
83
experiments/2024-12-09/src/operation/handle.rs
Normal file
@ -0,0 +1,83 @@
|
||||
use std::{cmp::Ordering, fmt, rc::Rc};
|
||||
|
||||
use crate::geometry::TriMesh;
|
||||
|
||||
use super::{HandleAny, Operation, OperationOutput};
|
||||
|
||||
pub struct Handle<T> {
|
||||
inner: Rc<dyn OperationOutput<T>>,
|
||||
}
|
||||
|
||||
impl<T> Handle<T> {
|
||||
pub fn new(inner: impl OperationOutput<T> + 'static) -> Self {
|
||||
Self {
|
||||
inner: Rc::new(inner),
|
||||
}
|
||||
}
|
||||
|
||||
pub fn to_any(&self) -> HandleAny {
|
||||
self.clone().into_any()
|
||||
}
|
||||
|
||||
pub fn into_any(self) -> HandleAny {
|
||||
HandleAny { inner: self.inner }
|
||||
}
|
||||
}
|
||||
|
||||
impl<T> Clone for Handle<T> {
|
||||
fn clone(&self) -> Self {
|
||||
Self {
|
||||
inner: self.inner.clone(),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl<T> Eq for Handle<T> {}
|
||||
|
||||
impl<T> Ord for Handle<T> {
|
||||
fn cmp(&self, other: &Self) -> Ordering {
|
||||
Rc::as_ptr(&self.inner)
|
||||
.cast::<()>()
|
||||
.cmp(&Rc::as_ptr(&other.inner).cast::<()>())
|
||||
}
|
||||
}
|
||||
|
||||
impl<T> PartialEq for Handle<T> {
|
||||
fn eq(&self, other: &Self) -> bool {
|
||||
Rc::ptr_eq(&self.inner, &other.inner)
|
||||
}
|
||||
}
|
||||
|
||||
impl<T> PartialOrd for Handle<T> {
|
||||
fn partial_cmp(&self, other: &Self) -> Option<Ordering> {
|
||||
Some(self.cmp(other))
|
||||
}
|
||||
}
|
||||
|
||||
impl<T> fmt::Debug for Handle<T> {
|
||||
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
|
||||
f.debug_struct("Handle")
|
||||
.field("inner", &Rc::as_ptr(&self.inner))
|
||||
.finish()
|
||||
}
|
||||
}
|
||||
|
||||
impl<T> Operation for Handle<T> {
|
||||
fn display(&self, f: &mut fmt::Formatter) -> fmt::Result {
|
||||
self.inner.display(f)
|
||||
}
|
||||
|
||||
fn tri_mesh(&self) -> TriMesh {
|
||||
self.inner.tri_mesh()
|
||||
}
|
||||
|
||||
fn children(&self) -> Vec<HandleAny> {
|
||||
self.inner.children()
|
||||
}
|
||||
}
|
||||
|
||||
impl<T> OperationOutput<T> for Handle<T> {
|
||||
fn output(&self) -> &T {
|
||||
self.inner.output()
|
||||
}
|
||||
}
|
@ -1,89 +1,15 @@
|
||||
mod handle;
|
||||
mod traits;
|
||||
|
||||
pub use self::traits::{Operation, OperationOutput};
|
||||
pub use self::{
|
||||
handle::Handle,
|
||||
traits::{Operation, OperationOutput},
|
||||
};
|
||||
|
||||
use std::{cmp::Ordering, fmt, rc::Rc};
|
||||
use std::{fmt, rc::Rc};
|
||||
|
||||
use crate::geometry::TriMesh;
|
||||
|
||||
pub struct Handle<T> {
|
||||
inner: Rc<dyn OperationOutput<T>>,
|
||||
}
|
||||
|
||||
impl<T> Handle<T> {
|
||||
pub fn new(inner: impl OperationOutput<T> + 'static) -> Self {
|
||||
Self {
|
||||
inner: Rc::new(inner),
|
||||
}
|
||||
}
|
||||
|
||||
pub fn to_any(&self) -> HandleAny {
|
||||
self.clone().into_any()
|
||||
}
|
||||
|
||||
pub fn into_any(self) -> HandleAny {
|
||||
HandleAny { inner: self.inner }
|
||||
}
|
||||
}
|
||||
|
||||
impl<T> Clone for Handle<T> {
|
||||
fn clone(&self) -> Self {
|
||||
Self {
|
||||
inner: self.inner.clone(),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl<T> Eq for Handle<T> {}
|
||||
|
||||
impl<T> Ord for Handle<T> {
|
||||
fn cmp(&self, other: &Self) -> Ordering {
|
||||
Rc::as_ptr(&self.inner)
|
||||
.cast::<()>()
|
||||
.cmp(&Rc::as_ptr(&other.inner).cast::<()>())
|
||||
}
|
||||
}
|
||||
|
||||
impl<T> PartialEq for Handle<T> {
|
||||
fn eq(&self, other: &Self) -> bool {
|
||||
Rc::ptr_eq(&self.inner, &other.inner)
|
||||
}
|
||||
}
|
||||
|
||||
impl<T> PartialOrd for Handle<T> {
|
||||
fn partial_cmp(&self, other: &Self) -> Option<Ordering> {
|
||||
Some(self.cmp(other))
|
||||
}
|
||||
}
|
||||
|
||||
impl<T> fmt::Debug for Handle<T> {
|
||||
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
|
||||
f.debug_struct("Handle")
|
||||
.field("inner", &Rc::as_ptr(&self.inner))
|
||||
.finish()
|
||||
}
|
||||
}
|
||||
|
||||
impl<T> Operation for Handle<T> {
|
||||
fn display(&self, f: &mut fmt::Formatter) -> fmt::Result {
|
||||
self.inner.display(f)
|
||||
}
|
||||
|
||||
fn tri_mesh(&self) -> TriMesh {
|
||||
self.inner.tri_mesh()
|
||||
}
|
||||
|
||||
fn children(&self) -> Vec<HandleAny> {
|
||||
self.inner.children()
|
||||
}
|
||||
}
|
||||
|
||||
impl<T> OperationOutput<T> for Handle<T> {
|
||||
fn output(&self) -> &T {
|
||||
self.inner.output()
|
||||
}
|
||||
}
|
||||
|
||||
#[derive(Clone)]
|
||||
pub struct HandleAny {
|
||||
inner: Rc<dyn Operation>,
|
||||
|
Loading…
Reference in New Issue
Block a user