mirror of
https://github.com/guilhermewerner/reflection
synced 2025-06-16 13:34:19 +00:00
Test generics and other things
This commit is contained in:
38
Source/Examples/Array.rs
Normal file
38
Source/Examples/Array.rs
Normal file
@ -0,0 +1,38 @@
|
||||
use crate::*;
|
||||
|
||||
#[derive(Reflect)]
|
||||
pub struct Array<T>
|
||||
where
|
||||
T: Reflect,
|
||||
{
|
||||
inner: Vec<T>,
|
||||
}
|
||||
|
||||
impl<T> Default for Array<T>
|
||||
where
|
||||
T: Reflect,
|
||||
{
|
||||
fn default() -> Self {
|
||||
Self { inner: Vec::new() }
|
||||
}
|
||||
}
|
||||
|
||||
impl<T> Array<T>
|
||||
where
|
||||
T: Reflect,
|
||||
{
|
||||
#[function]
|
||||
pub fn New() -> Self {
|
||||
Self::default()
|
||||
}
|
||||
|
||||
#[function]
|
||||
pub fn Get(&mut self, index: usize) -> Option<&T> {
|
||||
self.inner.get(index)
|
||||
}
|
||||
|
||||
#[function]
|
||||
pub fn GetMut(&mut self, index: usize) -> Option<&mut T> {
|
||||
self.inner.get_mut(index)
|
||||
}
|
||||
}
|
11
Source/Examples/BinaryHeap.rs
Normal file
11
Source/Examples/BinaryHeap.rs
Normal file
@ -0,0 +1,11 @@
|
||||
use crate::*;
|
||||
|
||||
#[derive(Reflect)]
|
||||
pub struct BinaryHeap<T>
|
||||
where
|
||||
T: Reflect,
|
||||
{
|
||||
inner: T,
|
||||
}
|
||||
|
||||
impl<T> BinaryHeap<T> where T: Reflect {}
|
11
Source/Examples/BinaryTree.rs
Normal file
11
Source/Examples/BinaryTree.rs
Normal file
@ -0,0 +1,11 @@
|
||||
use crate::*;
|
||||
|
||||
#[derive(Reflect)]
|
||||
pub struct BinaryTree<T>
|
||||
where
|
||||
T: Reflect,
|
||||
{
|
||||
inner: T,
|
||||
}
|
||||
|
||||
impl<T> BinaryTree<T> where T: Reflect {}
|
28
Source/Examples/HashMap.rs
Normal file
28
Source/Examples/HashMap.rs
Normal file
@ -0,0 +1,28 @@
|
||||
use crate::*;
|
||||
use std::collections::HashMap as InnerHashMap;
|
||||
use std::hash::Hash;
|
||||
|
||||
#[derive(Reflect)]
|
||||
pub struct HashMap<K, V>
|
||||
where
|
||||
K: Reflect + Eq + Hash,
|
||||
V: Reflect,
|
||||
{
|
||||
inner: InnerHashMap<K, V>,
|
||||
}
|
||||
|
||||
impl<K, V> HashMap<K, V>
|
||||
where
|
||||
K: Reflect + Eq + Hash,
|
||||
V: Reflect,
|
||||
{
|
||||
#[function]
|
||||
pub fn Insert(&mut self, key: K, value: V) -> Option<V> {
|
||||
self.inner.insert(key, value)
|
||||
}
|
||||
|
||||
#[function]
|
||||
pub fn Remove(&mut self, key: &K) -> Option<V> {
|
||||
self.inner.remove(key)
|
||||
}
|
||||
}
|
12
Source/Examples/HashSet.rs
Normal file
12
Source/Examples/HashSet.rs
Normal file
@ -0,0 +1,12 @@
|
||||
use crate::*;
|
||||
use std::collections::HashSet as InnerHashSet;
|
||||
|
||||
#[derive(Reflect)]
|
||||
pub struct HashSet<T>
|
||||
where
|
||||
T: Reflect,
|
||||
{
|
||||
inner: InnerHashSet<T>,
|
||||
}
|
||||
|
||||
impl<T> HashSet<T> where T: Reflect {}
|
11
Source/Examples/LinkedList.rs
Normal file
11
Source/Examples/LinkedList.rs
Normal file
@ -0,0 +1,11 @@
|
||||
use crate::*;
|
||||
|
||||
#[derive(Reflect)]
|
||||
pub struct LinkedList<T>
|
||||
where
|
||||
T: Reflect,
|
||||
{
|
||||
inner: T,
|
||||
}
|
||||
|
||||
impl<T> LinkedList<T> where T: Reflect {}
|
11
Source/Examples/Queue.rs
Normal file
11
Source/Examples/Queue.rs
Normal file
@ -0,0 +1,11 @@
|
||||
use crate::*;
|
||||
|
||||
#[derive(Reflect)]
|
||||
pub struct Queue<T>
|
||||
where
|
||||
T: Reflect,
|
||||
{
|
||||
inner: T,
|
||||
}
|
||||
|
||||
impl<T> Queue<T> where T: Reflect {}
|
48
Source/Examples/Stack.rs
Normal file
48
Source/Examples/Stack.rs
Normal file
@ -0,0 +1,48 @@
|
||||
use crate::*;
|
||||
|
||||
#[derive(Reflect)]
|
||||
pub struct Stack<T>
|
||||
where
|
||||
T: Reflect,
|
||||
{
|
||||
inner: Vec<T>,
|
||||
}
|
||||
|
||||
impl<T> Default for Stack<T>
|
||||
where
|
||||
T: Reflect,
|
||||
{
|
||||
fn default() -> Self {
|
||||
Self { inner: Vec::new() }
|
||||
}
|
||||
}
|
||||
|
||||
impl<T> Stack<T>
|
||||
where
|
||||
T: Reflect,
|
||||
{
|
||||
#[function]
|
||||
pub fn New() -> Self {
|
||||
Self::default()
|
||||
}
|
||||
|
||||
#[function]
|
||||
pub fn Push(&mut self, element: T) {
|
||||
self.inner.push(element);
|
||||
}
|
||||
|
||||
#[function]
|
||||
pub fn Peek(&mut self) -> Option<&T> {
|
||||
self.inner.last()
|
||||
}
|
||||
|
||||
#[function]
|
||||
pub fn PeekMut(&mut self) -> Option<&mut T> {
|
||||
self.inner.last_mut()
|
||||
}
|
||||
|
||||
#[function]
|
||||
pub fn Pop(&mut self) -> Option<T> {
|
||||
self.inner.pop()
|
||||
}
|
||||
}
|
@ -1,32 +1,31 @@
|
||||
use crate::*;
|
||||
#[path = "Array.rs"]
|
||||
mod _Array;
|
||||
pub use self::_Array::Array;
|
||||
|
||||
#[derive(Reflect)]
|
||||
pub struct Foo {
|
||||
#[property(visible, editable, category = "Default")]
|
||||
pub a: u32,
|
||||
#[path = "BinaryTree.rs"]
|
||||
mod _BinaryTree;
|
||||
pub use self::_BinaryTree::BinaryTree;
|
||||
|
||||
#[property(visible, editable, readwrite, category = "Default")]
|
||||
pub b: Bar,
|
||||
#[path = "BinaryHeap.rs"]
|
||||
mod _BinaryHeap;
|
||||
pub use self::_BinaryHeap::BinaryHeap;
|
||||
|
||||
#[property(visible, readonly, category = "Default")]
|
||||
pub c: Vec<u128>,
|
||||
#[path = "HashMap.rs"]
|
||||
mod _HashMap;
|
||||
pub use self::_HashMap::HashMap;
|
||||
|
||||
#[property(hidden)]
|
||||
pub d: Vec<Bar>,
|
||||
}
|
||||
#[path = "HashSet.rs"]
|
||||
mod _HashSet;
|
||||
pub use self::_HashSet::HashSet;
|
||||
|
||||
impl Foo {
|
||||
#[function(callable, multicast, category = "Default")]
|
||||
pub fn Func(&mut self) {}
|
||||
}
|
||||
#[path = "LinkedList.rs"]
|
||||
mod _LinkedList;
|
||||
pub use self::_LinkedList::LinkedList;
|
||||
|
||||
#[derive(Reflect)]
|
||||
pub struct Bar {
|
||||
#[property(visible, editable, category = "Default")]
|
||||
pub value: f32,
|
||||
}
|
||||
#[path = "Queue.rs"]
|
||||
mod _Queue;
|
||||
pub use self::_Queue::Queue;
|
||||
|
||||
impl Bar {
|
||||
#[function(event, server, reliable, category = "Default")]
|
||||
pub fn Func(&mut self) {}
|
||||
}
|
||||
#[path = "Stack.rs"]
|
||||
mod _Stack;
|
||||
pub use self::_Stack::Stack;
|
||||
|
Reference in New Issue
Block a user