mirror of
https://github.com/GraphiteEditor/Graphite.git
synced 2026-09-15 22:28:10 +08:00
Apply lints and cleanup to Rust code
This commit is contained in:
@@ -26,7 +26,7 @@ impl<'n, T: 'n + dyn_any::StaticTypeSized> FixedSizeStack<T> {
|
||||
pub fn new(capacity: usize) -> Self {
|
||||
let layout = std::alloc::Layout::array::<MaybeUninit<T>>(capacity).unwrap();
|
||||
let array = unsafe { std::alloc::alloc(layout) };
|
||||
let array = Box::into_pin(unsafe { Box::from_raw(std::slice::from_raw_parts_mut(array as *mut MaybeUninit<T>, capacity) as *mut [MaybeUninit<T>]) });
|
||||
let array = Box::into_pin(unsafe { Box::from_raw(core::ptr::slice_from_raw_parts_mut(array as *mut MaybeUninit<T>, capacity)) });
|
||||
|
||||
Self {
|
||||
data: array,
|
||||
|
||||
@@ -32,7 +32,7 @@ where
|
||||
type Output = Any<'n>;
|
||||
fn eval(self, input: Any<'n>) -> Self::Output {
|
||||
let node = core::any::type_name::<N>();
|
||||
let input: Box<I> = dyn_any::downcast(input).expect(format!("DynAnyNode Input in:\n{node}").as_str());
|
||||
let input: Box<I> = dyn_any::downcast(input).unwrap_or_else(|_| panic!("DynAnyNode Input in:\n{node}"));
|
||||
Box::new(self.0.eval(*input))
|
||||
}
|
||||
}
|
||||
@@ -43,7 +43,7 @@ where
|
||||
type Output = Any<'n>;
|
||||
fn eval(self, input: Any<'n>) -> Self::Output {
|
||||
let node = core::any::type_name::<N>();
|
||||
let input: Box<I> = dyn_any::downcast(input).expect(format!("DynAnyNode Input in:\n{node}").as_str());
|
||||
let input: Box<I> = dyn_any::downcast(input).unwrap_or_else(|_| panic!("DynAnyNode Input in:\n{node}"));
|
||||
Box::new((&self.0).eval_ref(*input))
|
||||
}
|
||||
}
|
||||
|
||||
@@ -26,6 +26,11 @@ impl<T> CacheNode<T> {
|
||||
CacheNode { cache: OnceCell::new() }
|
||||
}
|
||||
}
|
||||
impl<T> Default for CacheNode<T> {
|
||||
fn default() -> Self {
|
||||
Self::new()
|
||||
}
|
||||
}
|
||||
impl<T> Cache for CacheNode<T> {
|
||||
fn clear(&mut self) {
|
||||
self.cache = OnceCell::new();
|
||||
|
||||
@@ -134,7 +134,7 @@ pub fn export_image_node<'n>() -> impl Node<(Image, &'n str), Output = Result<()
|
||||
FnNode::new(|input: (Image, &str)| {
|
||||
let (image, path) = input;
|
||||
let mut new_image = image::ImageBuffer::new(image.width, image.height);
|
||||
for ((x, y, pixel), color) in new_image.enumerate_pixels_mut().zip((&image).data.iter()) {
|
||||
for ((x, y, pixel), color) in new_image.enumerate_pixels_mut().zip(image.data.iter()) {
|
||||
let color: Color = *color;
|
||||
assert!(x < image.width);
|
||||
assert!(y < image.height);
|
||||
|
||||
@@ -30,7 +30,7 @@ impl<'a, I: StaticTypeSized + Sync + Pod + Send, O: StaticTypeSized + Send + Syn
|
||||
fn execute(&self, input: Any<'static>) -> Result<Any<'static>, Box<dyn std::error::Error>> {
|
||||
let input = dyn_any::downcast::<Vec<I>>(input).expect("Wrong input type");
|
||||
let context = &self.context;
|
||||
let future = execute_shader(context.device.clone(), context.queue.clone(), self.shader.to_vec().into(), *input, self.entry_point.clone());
|
||||
let future = execute_shader(context.device.clone(), context.queue.clone(), self.shader.to_vec(), *input, self.entry_point.clone());
|
||||
let result = future_executor::block_on(future);
|
||||
|
||||
let result: Vec<O> = result.ok_or_else(|| String::from("Failed to execute shader"))?;
|
||||
|
||||
Reference in New Issue
Block a user