mirror of
https://github.com/guilhermewerner/reflection
synced 2025-06-16 21:44:19 +00:00
Test generics and other things
This commit is contained in:
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()
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user