pub struct ScreenshotCaptured {
pub entity: Entity,
pub image: Image,
}Fields§
§entity: Entity§image: ImageMethods from Deref<Target = Image>§
Sourcepub fn width(&self) -> u32
pub fn width(&self) -> u32
Returns the width of a 2D image.
Examples found in repository?
39fn atlas_render_system(
40 mut commands: Commands,
41 mut state: ResMut<State>,
42 font_atlas_set: Res<FontAtlasSet>,
43 images: Res<Assets<Image>>,
44) {
45 if let Some(font_atlases) = font_atlas_set.values().next() {
46 let x_offset = state.atlas_count as f32;
47 if state.atlas_count == font_atlases.len() as u32 {
48 return;
49 }
50 let font_atlas = &font_atlases[state.atlas_count as usize];
51 let image = images.get(&font_atlas.texture).unwrap();
52 state.atlas_count += 1;
53 commands.spawn((
54 ImageNode::new(font_atlas.texture.clone()),
55 Node {
56 position_type: PositionType::Absolute,
57 top: Val::ZERO,
58 left: px(image.width() as f32 * x_offset),
59 ..default()
60 },
61 ));
62 }
63}More examples
148fn asset_loaded(
149 asset_server: Res<AssetServer>,
150 mut images: ResMut<Assets<Image>>,
151 mut cubemap: ResMut<Cubemap>,
152 mut skyboxes: Query<&mut Skybox>,
153) {
154 if !cubemap.is_loaded && asset_server.load_state(&cubemap.image_handle).is_loaded() {
155 info!("Swapping to {}...", CUBEMAPS[cubemap.index].0);
156 let mut image = images.get_mut(&cubemap.image_handle).unwrap();
157 // NOTE: PNGs do not have any metadata that could indicate they contain a cubemap texture,
158 // so they appear as one texture. The following code reconfigures the texture as necessary.
159 if image.texture_descriptor.array_layer_count() == 1 {
160 let layers = image.height() / image.width();
161 image
162 .reinterpret_stacked_2d_as_array(layers)
163 .expect("asset should be 2d texture and height will always be evenly divisible with the given layers");
164 image.texture_view_descriptor = Some(TextureViewDescriptor {
165 dimension: Some(TextureViewDimension::Cube),
166 ..default()
167 });
168 }
169
170 for mut skybox in &mut skyboxes {
171 skybox.image = Some(cubemap.image_handle.clone());
172 }
173
174 cubemap.is_loaded = true;
175 }
176}450fn update(
451 images_to_save: Query<&ImageToSave>,
452 receiver: Res<MainWorldReceiver>,
453 mut images: ResMut<Assets<Image>>,
454 mut scene_controller: ResMut<SceneController>,
455 mut app_exit_writer: MessageWriter<AppExit>,
456 mut file_number: Local<u32>,
457) {
458 if let SceneState::Render(n) = scene_controller.state {
459 if n < 1 {
460 // We don't want to block the main world on this,
461 // so we use try_recv which attempts to receive without blocking
462 let mut image_data = Vec::new();
463 while let Ok(data) = receiver.try_recv() {
464 // image generation could be faster than saving to fs,
465 // that's why use only last of them
466 image_data = data;
467 }
468 if !image_data.is_empty() {
469 for image in images_to_save.iter() {
470 // Fill correct data from channel to image
471 let mut img_bytes = images.get_mut(image.id()).unwrap();
472
473 // We need to ensure that this works regardless of the image dimensions
474 // If the image became wider when copying from the texture to the buffer,
475 // then the data is reduced to its original size when copying from the buffer to the image.
476 let row_bytes = img_bytes.width() as usize
477 * img_bytes.texture_descriptor.format.pixel_size().unwrap();
478 let aligned_row_bytes = RenderDevice::align_copy_bytes_per_row(row_bytes);
479 if row_bytes == aligned_row_bytes {
480 img_bytes.data.as_mut().unwrap().clone_from(&image_data);
481 } else {
482 // shrink data to original image size
483 img_bytes.data = Some(
484 image_data
485 .chunks(aligned_row_bytes)
486 .take(img_bytes.height() as usize)
487 .flat_map(|row| &row[..row_bytes.min(row.len())])
488 .cloned()
489 .collect(),
490 );
491 }
492
493 // Create RGBA Image Buffer
494 let img = match img_bytes.clone().try_into_dynamic() {
495 Ok(img) => img.to_rgba8(),
496 Err(e) => panic!("Failed to create image buffer {e:?}"),
497 };
498
499 // Prepare directory for images, test_images in bevy folder is used here for example
500 // You should choose the path depending on your needs
501 let images_dir = PathBuf::from(env!("CARGO_MANIFEST_DIR")).join("test_images");
502 info!("Saving image to: {images_dir:?}");
503 std::fs::create_dir_all(&images_dir).unwrap();
504
505 // Choose filename starting from 000.png
506 let image_path = images_dir.join(format!("{:03}.png", file_number.deref()));
507 *file_number.deref_mut() += 1;
508
509 // Finally saving image to file, this heavy blocking operation is kept here
510 // for example simplicity, but in real app you should move it to a separate task
511 if let Err(e) = img.save(image_path) {
512 panic!("Failed to save image: {e}");
513 };
514 }
515 if scene_controller.single_image {
516 app_exit_writer.write(AppExit::Success);
517 }
518 }
519 } else {
520 // clears channel for skipped frames
521 while receiver.try_recv().is_ok() {}
522 scene_controller.state = SceneState::Render(n - 1);
523 }
524 }
525}Sourcepub fn height(&self) -> u32
pub fn height(&self) -> u32
Returns the height of a 2D image.
Examples found in repository?
148fn asset_loaded(
149 asset_server: Res<AssetServer>,
150 mut images: ResMut<Assets<Image>>,
151 mut cubemap: ResMut<Cubemap>,
152 mut skyboxes: Query<&mut Skybox>,
153) {
154 if !cubemap.is_loaded && asset_server.load_state(&cubemap.image_handle).is_loaded() {
155 info!("Swapping to {}...", CUBEMAPS[cubemap.index].0);
156 let mut image = images.get_mut(&cubemap.image_handle).unwrap();
157 // NOTE: PNGs do not have any metadata that could indicate they contain a cubemap texture,
158 // so they appear as one texture. The following code reconfigures the texture as necessary.
159 if image.texture_descriptor.array_layer_count() == 1 {
160 let layers = image.height() / image.width();
161 image
162 .reinterpret_stacked_2d_as_array(layers)
163 .expect("asset should be 2d texture and height will always be evenly divisible with the given layers");
164 image.texture_view_descriptor = Some(TextureViewDescriptor {
165 dimension: Some(TextureViewDimension::Cube),
166 ..default()
167 });
168 }
169
170 for mut skybox in &mut skyboxes {
171 skybox.image = Some(cubemap.image_handle.clone());
172 }
173
174 cubemap.is_loaded = true;
175 }
176}More examples
450fn update(
451 images_to_save: Query<&ImageToSave>,
452 receiver: Res<MainWorldReceiver>,
453 mut images: ResMut<Assets<Image>>,
454 mut scene_controller: ResMut<SceneController>,
455 mut app_exit_writer: MessageWriter<AppExit>,
456 mut file_number: Local<u32>,
457) {
458 if let SceneState::Render(n) = scene_controller.state {
459 if n < 1 {
460 // We don't want to block the main world on this,
461 // so we use try_recv which attempts to receive without blocking
462 let mut image_data = Vec::new();
463 while let Ok(data) = receiver.try_recv() {
464 // image generation could be faster than saving to fs,
465 // that's why use only last of them
466 image_data = data;
467 }
468 if !image_data.is_empty() {
469 for image in images_to_save.iter() {
470 // Fill correct data from channel to image
471 let mut img_bytes = images.get_mut(image.id()).unwrap();
472
473 // We need to ensure that this works regardless of the image dimensions
474 // If the image became wider when copying from the texture to the buffer,
475 // then the data is reduced to its original size when copying from the buffer to the image.
476 let row_bytes = img_bytes.width() as usize
477 * img_bytes.texture_descriptor.format.pixel_size().unwrap();
478 let aligned_row_bytes = RenderDevice::align_copy_bytes_per_row(row_bytes);
479 if row_bytes == aligned_row_bytes {
480 img_bytes.data.as_mut().unwrap().clone_from(&image_data);
481 } else {
482 // shrink data to original image size
483 img_bytes.data = Some(
484 image_data
485 .chunks(aligned_row_bytes)
486 .take(img_bytes.height() as usize)
487 .flat_map(|row| &row[..row_bytes.min(row.len())])
488 .cloned()
489 .collect(),
490 );
491 }
492
493 // Create RGBA Image Buffer
494 let img = match img_bytes.clone().try_into_dynamic() {
495 Ok(img) => img.to_rgba8(),
496 Err(e) => panic!("Failed to create image buffer {e:?}"),
497 };
498
499 // Prepare directory for images, test_images in bevy folder is used here for example
500 // You should choose the path depending on your needs
501 let images_dir = PathBuf::from(env!("CARGO_MANIFEST_DIR")).join("test_images");
502 info!("Saving image to: {images_dir:?}");
503 std::fs::create_dir_all(&images_dir).unwrap();
504
505 // Choose filename starting from 000.png
506 let image_path = images_dir.join(format!("{:03}.png", file_number.deref()));
507 *file_number.deref_mut() += 1;
508
509 // Finally saving image to file, this heavy blocking operation is kept here
510 // for example simplicity, but in real app you should move it to a separate task
511 if let Err(e) = img.save(image_path) {
512 panic!("Failed to save image: {e}");
513 };
514 }
515 if scene_controller.single_image {
516 app_exit_writer.write(AppExit::Success);
517 }
518 }
519 } else {
520 // clears channel for skipped frames
521 while receiver.try_recv().is_ok() {}
522 scene_controller.state = SceneState::Render(n - 1);
523 }
524 }
525}Sourcepub fn aspect_ratio(&self) -> AspectRatio
pub fn aspect_ratio(&self) -> AspectRatio
Returns the aspect ratio (width / height) of a 2D image.
Sourcepub fn size_f32(&self) -> Vec2
pub fn size_f32(&self) -> Vec2
Returns the size of a 2D image as f32.
Examples found in repository?
227fn resize_image(
228 image_mesh: Query<(&MeshMaterial3d<StandardMaterial>, &Mesh3d), With<HDRViewer>>,
229 materials: Res<Assets<StandardMaterial>>,
230 mut meshes: ResMut<Assets<Mesh>>,
231 images: Res<Assets<Image>>,
232 mut image_event_reader: MessageReader<AssetEvent<Image>>,
233) {
234 for event in image_event_reader.read() {
235 let (AssetEvent::Added { id } | AssetEvent::Modified { id }) = event else {
236 continue;
237 };
238
239 for (mat_h, mesh_h) in &image_mesh {
240 let Some(mat) = materials.get(mat_h) else {
241 continue;
242 };
243
244 let Some(ref base_color_texture) = mat.base_color_texture else {
245 continue;
246 };
247
248 if *id != base_color_texture.id() {
249 continue;
250 };
251
252 let Some(image_changed) = images.get(*id) else {
253 continue;
254 };
255
256 let size = image_changed.size_f32().normalize_or_zero() * 1.4;
257 // Resize Mesh
258 let quad = Mesh::from(Rectangle::from_size(size));
259 meshes.insert(mesh_h, quad).unwrap();
260 }
261 }
262}Sourcepub fn resize(&mut self, size: Extent3d)
pub fn resize(&mut self, size: Extent3d)
Resizes the image to the new size, by removing information or appending 0 to the data.
Does not properly scale the contents of the image.
If you need to keep pixel data intact, use Image::resize_in_place.
Examples found in repository?
84fn setup_camera(mut commands: Commands, mut images: ResMut<Assets<Image>>) {
85 let canvas_size = Extent3d {
86 width: RES_WIDTH,
87 height: RES_HEIGHT,
88 ..default()
89 };
90
91 // This Image serves as a canvas representing the low-resolution game screen
92 let mut canvas = Image {
93 texture_descriptor: TextureDescriptor {
94 label: None,
95 size: canvas_size,
96 dimension: TextureDimension::D2,
97 format: TextureFormat::Bgra8UnormSrgb,
98 mip_level_count: 1,
99 sample_count: 1,
100 usage: TextureUsages::TEXTURE_BINDING
101 | TextureUsages::COPY_DST
102 | TextureUsages::RENDER_ATTACHMENT,
103 view_formats: &[],
104 },
105 ..default()
106 };
107
108 // Fill image.data with zeroes
109 canvas.resize(canvas_size);
110
111 let image_handle = images.add(canvas);
112
113 // This camera renders whatever is on `PIXEL_PERFECT_LAYERS` to the canvas
114 commands.spawn((
115 Camera2d,
116 Camera {
117 // Render before the "main pass" camera
118 order: -1,
119 clear_color: ClearColorConfig::Custom(GRAY.into()),
120 ..default()
121 },
122 RenderTarget::Image(image_handle.clone().into()),
123 Msaa::Off,
124 InGameCamera,
125 PIXEL_PERFECT_LAYERS,
126 ));
127
128 // Spawn the canvas
129 commands.spawn((Sprite::from_image(image_handle), Canvas, HIGH_RES_LAYERS));
130
131 // The "outer" camera renders whatever is on `HIGH_RES_LAYERS` to the screen.
132 // here, the canvas and one of the sample sprites will be rendered by this camera
133 commands.spawn((Camera2d, Msaa::Off, OuterCamera, HIGH_RES_LAYERS));
134}Sourcepub fn reinterpret_size(
&mut self,
new_size: Extent3d,
) -> Result<(), TextureReinterpretationError>
pub fn reinterpret_size( &mut self, new_size: Extent3d, ) -> Result<(), TextureReinterpretationError>
Changes the size if the total number of data elements (pixels) remains the same.
If not, returns TextureReinterpretationError::IncompatibleSizes.
Sourcepub fn resize_in_place(&mut self, new_size: Extent3d)
pub fn resize_in_place(&mut self, new_size: Extent3d)
Resizes the image to the new size, keeping the pixel data intact, anchored at the top-left. When growing, the new space is filled with 0. When shrinking, the image is clipped.
For faster resizing when keeping pixel data intact is not important, use Image::resize.
Sourcepub fn reinterpret_stacked_2d_as_array(
&mut self,
layers: u32,
) -> Result<(), TextureReinterpretationError>
pub fn reinterpret_stacked_2d_as_array( &mut self, layers: u32, ) -> Result<(), TextureReinterpretationError>
Takes a 2D image containing vertically stacked images of the same size, and reinterprets
it as a 2D array texture, where each of the stacked images becomes one layer of the
array. This is primarily for use with the texture2DArray shader uniform type.
§Errors
Returns TextureReinterpretationError if the texture is not 2D, has more than one layers
or is not evenly dividable into the layers.
Examples found in repository?
148fn asset_loaded(
149 asset_server: Res<AssetServer>,
150 mut images: ResMut<Assets<Image>>,
151 mut cubemap: ResMut<Cubemap>,
152 mut skyboxes: Query<&mut Skybox>,
153) {
154 if !cubemap.is_loaded && asset_server.load_state(&cubemap.image_handle).is_loaded() {
155 info!("Swapping to {}...", CUBEMAPS[cubemap.index].0);
156 let mut image = images.get_mut(&cubemap.image_handle).unwrap();
157 // NOTE: PNGs do not have any metadata that could indicate they contain a cubemap texture,
158 // so they appear as one texture. The following code reconfigures the texture as necessary.
159 if image.texture_descriptor.array_layer_count() == 1 {
160 let layers = image.height() / image.width();
161 image
162 .reinterpret_stacked_2d_as_array(layers)
163 .expect("asset should be 2d texture and height will always be evenly divisible with the given layers");
164 image.texture_view_descriptor = Some(TextureViewDescriptor {
165 dimension: Some(TextureViewDimension::Cube),
166 ..default()
167 });
168 }
169
170 for mut skybox in &mut skyboxes {
171 skybox.image = Some(cubemap.image_handle.clone());
172 }
173
174 cubemap.is_loaded = true;
175 }
176}Sourcepub fn create_stacked_array_from_2d_grid(
&self,
rows: u32,
columns: u32,
) -> Result<Image, TextureReinterpretationError>
pub fn create_stacked_array_from_2d_grid( &self, rows: u32, columns: u32, ) -> Result<Image, TextureReinterpretationError>
Returns a newly constructed 2D image using the same properties as &self from a grid of tiles of the specified size, The new image is constructed in a vertical stack of tiles to be used as a 2D array texture.
This is primarily for preparing grid based tilesets.
§Errors
Returns TextureReinterpretationError if the texture is not 2D, has more than one layers
or is not evenly dividable by size_in_tiles.
Sourcepub fn convert(&self, new_format: TextureFormat) -> Option<Image>
pub fn convert(&self, new_format: TextureFormat) -> Option<Image>
Convert a texture from a format to another. Only a few formats are supported as input and output:
TextureFormat::R8UnormTextureFormat::Rg8UnormTextureFormat::Rgba8UnormSrgb
To get Image as a image::DynamicImage see:
Image::try_into_dynamic.
Sourcepub fn is_compressed(&self) -> bool
pub fn is_compressed(&self) -> bool
Whether the texture format is compressed or uncompressed
Sourcepub fn pixel_data_offset(
&self,
coords: UVec3,
) -> Result<usize, TextureAccessError>
pub fn pixel_data_offset( &self, coords: UVec3, ) -> Result<usize, TextureAccessError>
Compute the byte offset where the data of a specific pixel is stored
Returns an error if the provided coordinates are out of bounds.
For 2D textures, Z is the layer number. For 1D textures, Y and Z are ignored.
Sourcepub fn pixel_bytes(&self, coords: UVec3) -> Result<&[u8], TextureAccessError>
pub fn pixel_bytes(&self, coords: UVec3) -> Result<&[u8], TextureAccessError>
Get a reference to the data bytes where a specific pixel’s value is stored.
Sourcepub fn pixel_bytes_mut(
&mut self,
coords: UVec3,
) -> Result<&mut [u8], TextureAccessError>
pub fn pixel_bytes_mut( &mut self, coords: UVec3, ) -> Result<&mut [u8], TextureAccessError>
Get a mutable reference to the data bytes where a specific pixel’s value is stored.
Examples found in repository?
38fn setup(mut commands: Commands, mut images: ResMut<Assets<Image>>) {
39 commands.spawn(Camera2d);
40
41 // Create an image that we are going to draw into
42 let mut image = Image::new_fill(
43 // 2D image of size 256x256
44 Extent3d {
45 width: IMAGE_WIDTH,
46 height: IMAGE_HEIGHT,
47 depth_or_array_layers: 1,
48 },
49 TextureDimension::D2,
50 // Initialize it with a beige color
51 &(css::BEIGE.to_u8_array()),
52 // Use the same encoding as the color we set
53 TextureFormat::Rgba8UnormSrgb,
54 RenderAssetUsages::MAIN_WORLD | RenderAssetUsages::RENDER_WORLD,
55 );
56
57 // To make it extra fancy, we can set the Alpha of each pixel,
58 // so that it fades out in a circular fashion.
59 for y in 0..IMAGE_HEIGHT {
60 for x in 0..IMAGE_WIDTH {
61 let center = Vec2::new(IMAGE_WIDTH as f32 / 2.0, IMAGE_HEIGHT as f32 / 2.0);
62 let max_radius = IMAGE_HEIGHT.min(IMAGE_WIDTH) as f32 / 2.0;
63 let r = Vec2::new(x as f32, y as f32).distance(center);
64 let a = 1.0 - (r / max_radius).clamp(0.0, 1.0);
65
66 // Here we will set the A value by accessing the raw data bytes.
67 // (it is the 4th byte of each pixel, as per our `TextureFormat`)
68
69 // Find our pixel by its coordinates
70 let pixel_bytes = image.pixel_bytes_mut(UVec3::new(x, y, 0)).unwrap();
71 // Convert our f32 to u8
72 pixel_bytes[3] = (a * u8::MAX as f32) as u8;
73 }
74 }
75
76 // Add it to Bevy's assets, so it can be used for rendering
77 // this will give us a handle we can use
78 // (to display it in a sprite, or as part of UI, etc.)
79 let handle = images.add(image);
80
81 // Create a sprite entity using our image
82 commands.spawn(Sprite::from_image(handle.clone()));
83 commands.insert_resource(MyProcGenImage(handle));
84
85 // We're seeding the PRNG here to make this example deterministic for testing purposes.
86 // This isn't strictly required in practical use unless you need your app to be deterministic.
87 let seeded_rng = ChaCha8Rng::seed_from_u64(19878367467712);
88 commands.insert_resource(SeededRng(seeded_rng));
89}Sourcepub fn clear(&mut self, pixel: &[u8])
pub fn clear(&mut self, pixel: &[u8])
Clears the content of the image with the given pixel. The image needs to be initialized on the cpu otherwise this is a noop.
This does nothing if the image data is not already initialized
Sourcepub fn get_color_at_1d(&self, x: u32) -> Result<Color, TextureAccessError>
pub fn get_color_at_1d(&self, x: u32) -> Result<Color, TextureAccessError>
Read the color of a specific pixel (1D texture).
See get_color_at for more details.
Sourcepub fn get_color_at(&self, x: u32, y: u32) -> Result<Color, TextureAccessError>
pub fn get_color_at(&self, x: u32, y: u32) -> Result<Color, TextureAccessError>
Read the color of a specific pixel (2D texture).
This function will find the raw byte data of a specific pixel and
decode it into a user-friendly Color struct for you.
Supports many of the common TextureFormats:
- RGBA/BGRA 8-bit unsigned integer, both sRGB and Linear
- 16-bit and 32-bit unsigned integer
- 16-bit and 32-bit float
Be careful: as the data is converted to Color (which uses f32 internally),
there may be issues with precision when using non-f32 TextureFormats.
If you read a value you previously wrote using set_color_at, it will not match.
If you are working with a 32-bit integer TextureFormat, the value will be
inaccurate (as f32 does not have enough bits to represent it exactly).
Single channel (R) formats are assumed to represent grayscale, so the value
will be copied to all three RGB channels in the resulting Color.
Other TextureFormats are unsupported, such as:
- block-compressed formats
- non-byte-aligned formats like 10-bit
- signed integer formats
Examples found in repository?
92fn draw(
93 my_handle: Res<MyProcGenImage>,
94 mut images: ResMut<Assets<Image>>,
95 // Used to keep track of where we are
96 mut i: Local<u32>,
97 mut draw_color: Local<Color>,
98 mut seeded_rng: ResMut<SeededRng>,
99) {
100 if *i == 0 {
101 // Generate a random color on first run.
102 *draw_color = Color::linear_rgb(
103 seeded_rng.0.random(),
104 seeded_rng.0.random(),
105 seeded_rng.0.random(),
106 );
107 }
108
109 // Get the image from Bevy's asset storage.
110 let mut image = images.get_mut(&my_handle.0).expect("Image not found");
111
112 // Compute the position of the pixel to draw.
113
114 let center = Vec2::new(IMAGE_WIDTH as f32 / 2.0, IMAGE_HEIGHT as f32 / 2.0);
115 let max_radius = IMAGE_HEIGHT.min(IMAGE_WIDTH) as f32 / 2.0;
116 let rot_speed = 0.0123;
117 let period = 0.12345;
118
119 let r = ops::sin(*i as f32 * period) * max_radius;
120 let xy = Vec2::from_angle(*i as f32 * rot_speed) * r + center;
121 let (x, y) = (xy.x as u32, xy.y as u32);
122
123 // Get the old color of that pixel.
124 let old_color = image.get_color_at(x, y).unwrap();
125
126 // If the old color is our current color, change our drawing color.
127 let tolerance = 1.0 / 255.0;
128 if old_color.distance(&draw_color) <= tolerance {
129 *draw_color = Color::linear_rgb(
130 seeded_rng.0.random(),
131 seeded_rng.0.random(),
132 seeded_rng.0.random(),
133 );
134 }
135
136 // Set the new color, but keep old alpha value from image.
137 image
138 .set_color_at(x, y, draw_color.with_alpha(old_color.alpha()))
139 .unwrap();
140
141 *i += 1;
142}Sourcepub fn get_color_at_3d(
&self,
x: u32,
y: u32,
z: u32,
) -> Result<Color, TextureAccessError>
pub fn get_color_at_3d( &self, x: u32, y: u32, z: u32, ) -> Result<Color, TextureAccessError>
Read the color of a specific pixel (2D texture with layers or 3D texture).
See get_color_at for more details.
Sourcepub fn set_color_at_1d(
&mut self,
x: u32,
color: Color,
) -> Result<(), TextureAccessError>
pub fn set_color_at_1d( &mut self, x: u32, color: Color, ) -> Result<(), TextureAccessError>
Change the color of a specific pixel (1D texture).
See set_color_at for more details.
Sourcepub fn set_color_at(
&mut self,
x: u32,
y: u32,
color: Color,
) -> Result<(), TextureAccessError>
pub fn set_color_at( &mut self, x: u32, y: u32, color: Color, ) -> Result<(), TextureAccessError>
Change the color of a specific pixel (2D texture).
This function will find the raw byte data of a specific pixel and
change it according to a Color you provide. The Color struct
will be encoded into the Image’s TextureFormat.
Supports many of the common TextureFormats:
- RGBA/BGRA 8-bit unsigned integer, both sRGB and Linear
- 16-bit and 32-bit unsigned integer (with possibly-limited precision, as
Colorusesf32) - 16-bit and 32-bit float
Be careful: writing to non-f32 TextureFormats is lossy! The data has to be converted,
so if you read it back using get_color_at, the Color you get will not equal the value
you used when writing it using this function.
For RG formats, only the respective values from the linear RGB Color will be used.
For R formats the linear RGB Color will be converted to grayscale
and the R channel will be the luminance.
Other TextureFormats are unsupported, such as:
- block-compressed formats
- non-byte-aligned formats like 10-bit
- signed integer formats
Examples found in repository?
208fn try_plot(
209 event: On<TryPlot>,
210 sprite: Query<(&Sprite, &Anchor, &GlobalTransform), With<SpriteToSave>>,
211 camera: Single<(&Camera, &GlobalTransform)>,
212 texture_atlases: Res<Assets<TextureAtlasLayout>>,
213 draw_color: Res<DrawColor>,
214 mut images: ResMut<Assets<Image>>,
215) {
216 let Ok((sprite, anchor, sprite_transform)) = sprite.get(event.entity) else {
217 return;
218 };
219 let (camera, camera_transform) = camera.into_inner();
220 let Ok(world_position) = camera.viewport_to_world_2d(camera_transform, event.location.position)
221 else {
222 return;
223 };
224 let relative_to_sprite = sprite_transform
225 .affine()
226 .inverse()
227 .transform_point3(world_position.extend(0.0));
228 let Ok(pixel_space) = sprite.compute_pixel_space_point(
229 relative_to_sprite.xy(),
230 *anchor,
231 &images,
232 &texture_atlases,
233 ) else {
234 return;
235 };
236 let pixel_coordinates = pixel_space.floor().as_uvec2();
237 let mut image = images.get_mut(&sprite.image).unwrap();
238 // For an actual drawing app, you'd at least draw a line from the last point, but this is
239 // simpler.
240 image
241 .set_color_at(pixel_coordinates.x, pixel_coordinates.y, draw_color.0)
242 .unwrap();
243}More examples
92fn draw(
93 my_handle: Res<MyProcGenImage>,
94 mut images: ResMut<Assets<Image>>,
95 // Used to keep track of where we are
96 mut i: Local<u32>,
97 mut draw_color: Local<Color>,
98 mut seeded_rng: ResMut<SeededRng>,
99) {
100 if *i == 0 {
101 // Generate a random color on first run.
102 *draw_color = Color::linear_rgb(
103 seeded_rng.0.random(),
104 seeded_rng.0.random(),
105 seeded_rng.0.random(),
106 );
107 }
108
109 // Get the image from Bevy's asset storage.
110 let mut image = images.get_mut(&my_handle.0).expect("Image not found");
111
112 // Compute the position of the pixel to draw.
113
114 let center = Vec2::new(IMAGE_WIDTH as f32 / 2.0, IMAGE_HEIGHT as f32 / 2.0);
115 let max_radius = IMAGE_HEIGHT.min(IMAGE_WIDTH) as f32 / 2.0;
116 let rot_speed = 0.0123;
117 let period = 0.12345;
118
119 let r = ops::sin(*i as f32 * period) * max_radius;
120 let xy = Vec2::from_angle(*i as f32 * rot_speed) * r + center;
121 let (x, y) = (xy.x as u32, xy.y as u32);
122
123 // Get the old color of that pixel.
124 let old_color = image.get_color_at(x, y).unwrap();
125
126 // If the old color is our current color, change our drawing color.
127 let tolerance = 1.0 / 255.0;
128 if old_color.distance(&draw_color) <= tolerance {
129 *draw_color = Color::linear_rgb(
130 seeded_rng.0.random(),
131 seeded_rng.0.random(),
132 seeded_rng.0.random(),
133 );
134 }
135
136 // Set the new color, but keep old alpha value from image.
137 image
138 .set_color_at(x, y, draw_color.with_alpha(old_color.alpha()))
139 .unwrap();
140
141 *i += 1;
142}Sourcepub fn set_color_at_3d(
&mut self,
x: u32,
y: u32,
z: u32,
color: Color,
) -> Result<(), TextureAccessError>
pub fn set_color_at_3d( &mut self, x: u32, y: u32, z: u32, color: Color, ) -> Result<(), TextureAccessError>
Change the color of a specific pixel (2D texture with layers or 3D texture).
See set_color_at for more details.
Trait Implementations§
Source§impl Debug for ScreenshotCaptured
impl Debug for ScreenshotCaptured
Source§impl Deref for ScreenshotCaptured
impl Deref for ScreenshotCaptured
Source§impl DerefMut for ScreenshotCaptured
impl DerefMut for ScreenshotCaptured
Source§impl EntityEvent for ScreenshotCaptured
impl EntityEvent for ScreenshotCaptured
Source§fn event_target(&self) -> Entity
fn event_target(&self) -> Entity
Entity “target” of this EntityEvent. When triggered, this will run observers that watch for this specific entity.Source§impl Event for ScreenshotCaptured
impl Event for ScreenshotCaptured
Source§type Trigger<'a> = EntityTrigger
type Trigger<'a> = EntityTrigger
Trigger for more info.Source§impl FromArg for ScreenshotCaptured
impl FromArg for ScreenshotCaptured
Source§impl FromReflect for ScreenshotCaptured
impl FromReflect for ScreenshotCaptured
Source§fn from_reflect(
reflect: &(dyn PartialReflect + 'static),
) -> Option<ScreenshotCaptured>
fn from_reflect( reflect: &(dyn PartialReflect + 'static), ) -> Option<ScreenshotCaptured>
Self from a reflected value.Source§fn take_from_reflect(
reflect: Box<dyn PartialReflect>,
) -> Result<Self, Box<dyn PartialReflect>>
fn take_from_reflect( reflect: Box<dyn PartialReflect>, ) -> Result<Self, Box<dyn PartialReflect>>
Self using,
constructing the value using from_reflect if that fails. Read moreSource§impl GetOwnership for ScreenshotCaptured
impl GetOwnership for ScreenshotCaptured
Source§impl GetTypeRegistration for ScreenshotCaptured
impl GetTypeRegistration for ScreenshotCaptured
Source§fn get_type_registration() -> TypeRegistration
fn get_type_registration() -> TypeRegistration
TypeRegistration for this type.Source§fn register_type_dependencies(registry: &mut TypeRegistry)
fn register_type_dependencies(registry: &mut TypeRegistry)
Source§impl IntoReturn for ScreenshotCaptured
impl IntoReturn for ScreenshotCaptured
Source§fn into_return<'into_return>(self) -> Return<'into_return>where
ScreenshotCaptured: 'into_return,
fn into_return<'into_return>(self) -> Return<'into_return>where
ScreenshotCaptured: 'into_return,
Source§impl PartialReflect for ScreenshotCaptured
impl PartialReflect for ScreenshotCaptured
Source§fn get_represented_type_info(&self) -> Option<&'static TypeInfo>
fn get_represented_type_info(&self) -> Option<&'static TypeInfo>
Source§fn try_apply(
&mut self,
value: &(dyn PartialReflect + 'static),
) -> Result<(), ApplyError>
fn try_apply( &mut self, value: &(dyn PartialReflect + 'static), ) -> Result<(), ApplyError>
Source§fn reflect_kind(&self) -> ReflectKind
fn reflect_kind(&self) -> ReflectKind
Source§fn reflect_ref(&self) -> ReflectRef<'_>
fn reflect_ref(&self) -> ReflectRef<'_>
Source§fn reflect_mut(&mut self) -> ReflectMut<'_>
fn reflect_mut(&mut self) -> ReflectMut<'_>
Source§fn reflect_owned(self: Box<ScreenshotCaptured>) -> ReflectOwned
fn reflect_owned(self: Box<ScreenshotCaptured>) -> ReflectOwned
Source§fn try_into_reflect(
self: Box<ScreenshotCaptured>,
) -> Result<Box<dyn Reflect>, Box<dyn PartialReflect>>
fn try_into_reflect( self: Box<ScreenshotCaptured>, ) -> Result<Box<dyn Reflect>, Box<dyn PartialReflect>>
Source§fn try_as_reflect(&self) -> Option<&(dyn Reflect + 'static)>
fn try_as_reflect(&self) -> Option<&(dyn Reflect + 'static)>
Source§fn try_as_reflect_mut(&mut self) -> Option<&mut (dyn Reflect + 'static)>
fn try_as_reflect_mut(&mut self) -> Option<&mut (dyn Reflect + 'static)>
Source§fn into_partial_reflect(
self: Box<ScreenshotCaptured>,
) -> Box<dyn PartialReflect>
fn into_partial_reflect( self: Box<ScreenshotCaptured>, ) -> Box<dyn PartialReflect>
Source§fn as_partial_reflect(&self) -> &(dyn PartialReflect + 'static)
fn as_partial_reflect(&self) -> &(dyn PartialReflect + 'static)
Source§fn as_partial_reflect_mut(&mut self) -> &mut (dyn PartialReflect + 'static)
fn as_partial_reflect_mut(&mut self) -> &mut (dyn PartialReflect + 'static)
Source§fn reflect_partial_eq(
&self,
value: &(dyn PartialReflect + 'static),
) -> Option<bool>
fn reflect_partial_eq( &self, value: &(dyn PartialReflect + 'static), ) -> Option<bool>
Source§fn reflect_partial_cmp(
&self,
value: &(dyn PartialReflect + 'static),
) -> Option<Ordering>
fn reflect_partial_cmp( &self, value: &(dyn PartialReflect + 'static), ) -> Option<Ordering>
Source§fn debug(&self, f: &mut Formatter<'_>) -> Result<(), Error>
fn debug(&self, f: &mut Formatter<'_>) -> Result<(), Error>
Source§fn reflect_clone(&self) -> Result<Box<dyn Reflect>, ReflectCloneError>
fn reflect_clone(&self) -> Result<Box<dyn Reflect>, ReflectCloneError>
Self using reflection. Read moreSource§fn apply(&mut self, value: &(dyn PartialReflect + 'static))
fn apply(&mut self, value: &(dyn PartialReflect + 'static))
Source§fn to_dynamic(&self) -> Box<dyn PartialReflect>
fn to_dynamic(&self) -> Box<dyn PartialReflect>
Source§fn reflect_clone_and_take<T>(&self) -> Result<T, ReflectCloneError>
fn reflect_clone_and_take<T>(&self) -> Result<T, ReflectCloneError>
PartialReflect, combines reflect_clone and
take in a useful fashion, automatically constructing an appropriate
ReflectCloneError if the downcast fails.Source§fn reflect_hash(&self) -> Option<u64>
fn reflect_hash(&self) -> Option<u64>
Source§fn is_dynamic(&self) -> bool
fn is_dynamic(&self) -> bool
Source§impl Reflect for ScreenshotCaptured
impl Reflect for ScreenshotCaptured
Source§fn into_any(self: Box<ScreenshotCaptured>) -> Box<dyn Any>
fn into_any(self: Box<ScreenshotCaptured>) -> Box<dyn Any>
Box<dyn Any>. Read moreSource§fn as_any_mut(&mut self) -> &mut (dyn Any + 'static)
fn as_any_mut(&mut self) -> &mut (dyn Any + 'static)
&mut dyn Any. Read moreSource§fn into_reflect(self: Box<ScreenshotCaptured>) -> Box<dyn Reflect>
fn into_reflect(self: Box<ScreenshotCaptured>) -> Box<dyn Reflect>
Source§fn as_reflect(&self) -> &(dyn Reflect + 'static)
fn as_reflect(&self) -> &(dyn Reflect + 'static)
Source§fn as_reflect_mut(&mut self) -> &mut (dyn Reflect + 'static)
fn as_reflect_mut(&mut self) -> &mut (dyn Reflect + 'static)
Source§impl Struct for ScreenshotCaptured
impl Struct for ScreenshotCaptured
Source§fn field(&self, name: &str) -> Option<&(dyn PartialReflect + 'static)>
fn field(&self, name: &str) -> Option<&(dyn PartialReflect + 'static)>
name as a &dyn PartialReflect.Source§fn field_mut(
&mut self,
name: &str,
) -> Option<&mut (dyn PartialReflect + 'static)>
fn field_mut( &mut self, name: &str, ) -> Option<&mut (dyn PartialReflect + 'static)>
name as a
&mut dyn PartialReflect.Source§fn field_at(&self, index: usize) -> Option<&(dyn PartialReflect + 'static)>
fn field_at(&self, index: usize) -> Option<&(dyn PartialReflect + 'static)>
index as a
&dyn PartialReflect.Source§fn field_at_mut(
&mut self,
index: usize,
) -> Option<&mut (dyn PartialReflect + 'static)>
fn field_at_mut( &mut self, index: usize, ) -> Option<&mut (dyn PartialReflect + 'static)>
index
as a &mut dyn PartialReflect.Source§fn index_of_name(&self, name: &str) -> Option<usize>
fn index_of_name(&self, name: &str) -> Option<usize>
Source§fn iter_fields(&self) -> FieldIter<'_> ⓘ
fn iter_fields(&self) -> FieldIter<'_> ⓘ
Source§fn to_dynamic_struct(&self) -> DynamicStruct
fn to_dynamic_struct(&self) -> DynamicStruct
DynamicStruct from this struct.Source§fn get_represented_struct_info(&self) -> Option<&'static StructInfo>
fn get_represented_struct_info(&self) -> Option<&'static StructInfo>
None if TypeInfo is not available.Source§impl TypePath for ScreenshotCaptured
impl TypePath for ScreenshotCaptured
Source§fn type_path() -> &'static str
fn type_path() -> &'static str
Source§fn short_type_path() -> &'static str
fn short_type_path() -> &'static str
Source§fn type_ident() -> Option<&'static str>
fn type_ident() -> Option<&'static str>
Source§fn crate_name() -> Option<&'static str>
fn crate_name() -> Option<&'static str>
Auto Trait Implementations§
impl Freeze for ScreenshotCaptured
impl RefUnwindSafe for ScreenshotCaptured
impl Send for ScreenshotCaptured
impl Sync for ScreenshotCaptured
impl Unpin for ScreenshotCaptured
impl UnsafeUnpin for ScreenshotCaptured
impl UnwindSafe for ScreenshotCaptured
Blanket Implementations§
Source§impl<T, U> AsBindGroupShaderType<U> for T
impl<T, U> AsBindGroupShaderType<U> for T
Source§fn as_bind_group_shader_type(&self, _images: &RenderAssets<GpuImage>) -> U
fn as_bind_group_shader_type(&self, _images: &RenderAssets<GpuImage>) -> U
T ShaderType for self. When used in AsBindGroup
derives, it is safe to assume that all images in self exist.Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
impl<ST, DT> CastableFrom<ST, Initialized, Initialized> for DT
impl<ST, DT> CastableFrom<ST, Uninit, Uninit> for DT
impl<T> ConditionalSend for Twhere
T: Send,
Source§impl<T> Downcast for Twhere
T: Any,
impl<T> Downcast for Twhere
T: Any,
Source§fn into_any(self: Box<T>) -> Box<dyn Any>
fn into_any(self: Box<T>) -> Box<dyn Any>
Box<dyn Trait> (where Trait: Downcast) to Box<dyn Any>, which can then be
downcast into Box<dyn ConcreteType> where ConcreteType implements Trait.Source§fn into_any_rc(self: Rc<T>) -> Rc<dyn Any>
fn into_any_rc(self: Rc<T>) -> Rc<dyn Any>
Rc<Trait> (where Trait: Downcast) to Rc<Any>, which can then be further
downcast into Rc<ConcreteType> where ConcreteType implements Trait.Source§fn as_any(&self) -> &(dyn Any + 'static)
fn as_any(&self) -> &(dyn Any + 'static)
&Trait (where Trait: Downcast) to &Any. This is needed since Rust cannot
generate &Any’s vtable from &Trait’s.Source§fn as_any_mut(&mut self) -> &mut (dyn Any + 'static)
fn as_any_mut(&mut self) -> &mut (dyn Any + 'static)
&mut Trait (where Trait: Downcast) to &Any. This is needed since Rust cannot
generate &mut Any’s vtable from &mut Trait’s.Source§impl<T> Downcast for Twhere
T: Any,
impl<T> Downcast for Twhere
T: Any,
Source§fn into_any(self: Box<T>) -> Box<dyn Any>
fn into_any(self: Box<T>) -> Box<dyn Any>
Box<dyn Trait> (where Trait: Downcast) to Box<dyn Any>. Box<dyn Any> can
then be further downcast into Box<ConcreteType> where ConcreteType implements Trait.Source§fn into_any_rc(self: Rc<T>) -> Rc<dyn Any>
fn into_any_rc(self: Rc<T>) -> Rc<dyn Any>
Rc<Trait> (where Trait: Downcast) to Rc<Any>. Rc<Any> can then be
further downcast into Rc<ConcreteType> where ConcreteType implements Trait.Source§fn as_any(&self) -> &(dyn Any + 'static)
fn as_any(&self) -> &(dyn Any + 'static)
&Trait (where Trait: Downcast) to &Any. This is needed since Rust cannot
generate &Any’s vtable from &Trait’s.Source§fn as_any_mut(&mut self) -> &mut (dyn Any + 'static)
fn as_any_mut(&mut self) -> &mut (dyn Any + 'static)
&mut Trait (where Trait: Downcast) to &Any. This is needed since Rust cannot
generate &mut Any’s vtable from &mut Trait’s.Source§impl<T> DowncastSend for T
impl<T> DowncastSend for T
Source§impl<T> DowncastSync for T
impl<T> DowncastSync for T
impl<S, T> Duplex<S> for Twhere
T: FromSample<S> + ToSample<S>,
Source§impl<T> DynamicTypePath for Twhere
T: TypePath,
impl<T> DynamicTypePath for Twhere
T: TypePath,
Source§fn reflect_type_path(&self) -> &str
fn reflect_type_path(&self) -> &str
TypePath::type_path.Source§fn reflect_short_type_path(&self) -> &str
fn reflect_short_type_path(&self) -> &str
Source§fn reflect_type_ident(&self) -> Option<&str>
fn reflect_type_ident(&self) -> Option<&str>
TypePath::type_ident.Source§fn reflect_crate_name(&self) -> Option<&str>
fn reflect_crate_name(&self) -> Option<&str>
TypePath::crate_name.Source§fn reflect_module_path(&self) -> Option<&str>
fn reflect_module_path(&self) -> Option<&str>
Source§impl<T> DynamicTyped for Twhere
T: Typed,
impl<T> DynamicTyped for Twhere
T: Typed,
Source§fn reflect_type_info(&self) -> &'static TypeInfo
fn reflect_type_info(&self) -> &'static TypeInfo
Typed::type_info.impl<T> ErasedDestructor for Twhere
T: 'static,
Source§impl<T> FmtForward for T
impl<T> FmtForward for T
Source§fn fmt_binary(self) -> FmtBinary<Self>where
Self: Binary,
fn fmt_binary(self) -> FmtBinary<Self>where
Self: Binary,
self to use its Binary implementation when Debug-formatted.Source§fn fmt_display(self) -> FmtDisplay<Self>where
Self: Display,
fn fmt_display(self) -> FmtDisplay<Self>where
Self: Display,
self to use its Display implementation when
Debug-formatted.Source§fn fmt_lower_exp(self) -> FmtLowerExp<Self>where
Self: LowerExp,
fn fmt_lower_exp(self) -> FmtLowerExp<Self>where
Self: LowerExp,
self to use its LowerExp implementation when
Debug-formatted.Source§fn fmt_lower_hex(self) -> FmtLowerHex<Self>where
Self: LowerHex,
fn fmt_lower_hex(self) -> FmtLowerHex<Self>where
Self: LowerHex,
self to use its LowerHex implementation when
Debug-formatted.Source§fn fmt_octal(self) -> FmtOctal<Self>where
Self: Octal,
fn fmt_octal(self) -> FmtOctal<Self>where
Self: Octal,
self to use its Octal implementation when Debug-formatted.Source§fn fmt_pointer(self) -> FmtPointer<Self>where
Self: Pointer,
fn fmt_pointer(self) -> FmtPointer<Self>where
Self: Pointer,
self to use its Pointer implementation when
Debug-formatted.Source§fn fmt_upper_exp(self) -> FmtUpperExp<Self>where
Self: UpperExp,
fn fmt_upper_exp(self) -> FmtUpperExp<Self>where
Self: UpperExp,
self to use its UpperExp implementation when
Debug-formatted.Source§fn fmt_upper_hex(self) -> FmtUpperHex<Self>where
Self: UpperHex,
fn fmt_upper_hex(self) -> FmtUpperHex<Self>where
Self: UpperHex,
self to use its UpperHex implementation when
Debug-formatted.Source§impl<S> FromSample<S> for S
impl<S> FromSample<S> for S
fn from_sample_(s: S) -> S
Source§impl<S> GetField for Swhere
S: Struct,
impl<S> GetField for Swhere
S: Struct,
Source§impl<T> GetPath for T
impl<T> GetPath for T
Source§fn reflect_path<'p>(
&self,
path: impl ReflectPath<'p>,
) -> Result<&(dyn PartialReflect + 'static), ReflectPathError<'p>>
fn reflect_path<'p>( &self, path: impl ReflectPath<'p>, ) -> Result<&(dyn PartialReflect + 'static), ReflectPathError<'p>>
path. Read moreSource§fn reflect_path_mut<'p>(
&mut self,
path: impl ReflectPath<'p>,
) -> Result<&mut (dyn PartialReflect + 'static), ReflectPathError<'p>>
fn reflect_path_mut<'p>( &mut self, path: impl ReflectPath<'p>, ) -> Result<&mut (dyn PartialReflect + 'static), ReflectPathError<'p>>
path. Read moreSource§fn path<'p, T>(
&self,
path: impl ReflectPath<'p>,
) -> Result<&T, ReflectPathError<'p>>where
T: Reflect,
fn path<'p, T>(
&self,
path: impl ReflectPath<'p>,
) -> Result<&T, ReflectPathError<'p>>where
T: Reflect,
path. Read moreSource§fn path_mut<'p, T>(
&mut self,
path: impl ReflectPath<'p>,
) -> Result<&mut T, ReflectPathError<'p>>where
T: Reflect,
fn path_mut<'p, T>(
&mut self,
path: impl ReflectPath<'p>,
) -> Result<&mut T, ReflectPathError<'p>>where
T: Reflect,
path. Read moreSource§impl<T, W> HasTypeWitness<W> for Twhere
W: MakeTypeWitness<Arg = T>,
T: ?Sized,
impl<T, W> HasTypeWitness<W> for Twhere
W: MakeTypeWitness<Arg = T>,
T: ?Sized,
impl<T> HitDataExtra for T
Source§impl<T> Identity for Twhere
T: ?Sized,
impl<T> Identity for Twhere
T: ?Sized,
Source§impl<T> InitializeFromFunction<T> for T
impl<T> InitializeFromFunction<T> for T
Source§fn initialize_from_function(f: fn() -> T) -> T
fn initialize_from_function(f: fn() -> T) -> T
Source§impl<T> Instrument for T
impl<T> Instrument for T
Source§fn instrument(self, span: Span) -> Instrumented<Self> ⓘ
fn instrument(self, span: Span) -> Instrumented<Self> ⓘ
Source§fn in_current_span(self) -> Instrumented<Self> ⓘ
fn in_current_span(self) -> Instrumented<Self> ⓘ
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self> ⓘ
fn into_either(self, into_left: bool) -> Either<Self, Self> ⓘ
self into a Left variant of Either<Self, Self>
if into_left is true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self> ⓘ
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self> ⓘ
self into a Left variant of Either<Self, Self>
if into_left(&self) returns true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§impl<T> IntoResult<T> for T
impl<T> IntoResult<T> for T
Source§fn into_result(self) -> Result<T, RunSystemError>
fn into_result(self) -> Result<T, RunSystemError>
Source§impl<F, T> IntoSample<T> for Fwhere
T: FromSample<F>,
impl<F, T> IntoSample<T> for Fwhere
T: FromSample<F>,
fn into_sample(self) -> T
Source§impl<T> Pipe for Twhere
T: ?Sized,
impl<T> Pipe for Twhere
T: ?Sized,
Source§fn pipe<R>(self, func: impl FnOnce(Self) -> R) -> Rwhere
Self: Sized,
fn pipe<R>(self, func: impl FnOnce(Self) -> R) -> Rwhere
Self: Sized,
Source§fn pipe_ref<'a, R>(&'a self, func: impl FnOnce(&'a Self) -> R) -> Rwhere
R: 'a,
fn pipe_ref<'a, R>(&'a self, func: impl FnOnce(&'a Self) -> R) -> Rwhere
R: 'a,
self and passes that borrow into the pipe function. Read moreSource§fn pipe_ref_mut<'a, R>(&'a mut self, func: impl FnOnce(&'a mut Self) -> R) -> Rwhere
R: 'a,
fn pipe_ref_mut<'a, R>(&'a mut self, func: impl FnOnce(&'a mut Self) -> R) -> Rwhere
R: 'a,
self and passes that borrow into the pipe function. Read moreSource§fn pipe_borrow<'a, B, R>(&'a self, func: impl FnOnce(&'a B) -> R) -> R
fn pipe_borrow<'a, B, R>(&'a self, func: impl FnOnce(&'a B) -> R) -> R
Source§fn pipe_borrow_mut<'a, B, R>(
&'a mut self,
func: impl FnOnce(&'a mut B) -> R,
) -> R
fn pipe_borrow_mut<'a, B, R>( &'a mut self, func: impl FnOnce(&'a mut B) -> R, ) -> R
Source§fn pipe_as_ref<'a, U, R>(&'a self, func: impl FnOnce(&'a U) -> R) -> R
fn pipe_as_ref<'a, U, R>(&'a self, func: impl FnOnce(&'a U) -> R) -> R
self, then passes self.as_ref() into the pipe function.Source§fn pipe_as_mut<'a, U, R>(&'a mut self, func: impl FnOnce(&'a mut U) -> R) -> R
fn pipe_as_mut<'a, U, R>(&'a mut self, func: impl FnOnce(&'a mut U) -> R) -> R
self, then passes self.as_mut() into the pipe
function.Source§fn pipe_deref<'a, T, R>(&'a self, func: impl FnOnce(&'a T) -> R) -> R
fn pipe_deref<'a, T, R>(&'a self, func: impl FnOnce(&'a T) -> R) -> R
self, then passes self.deref() into the pipe function.impl<T> Read<Exclusive, BecauseExclusive> for Twhere
T: ?Sized,
impl<T> Reflectable for T
impl<T> Settings for T
Source§impl<Ret> SpawnIfAsync<(), Ret> for Ret
impl<Ret> SpawnIfAsync<(), Ret> for Ret
Source§impl<T, O> SuperFrom<T> for Owhere
O: From<T>,
impl<T, O> SuperFrom<T> for Owhere
O: From<T>,
Source§fn super_from(input: T) -> O
fn super_from(input: T) -> O
Source§impl<T, O, M> SuperInto<O, M> for Twhere
O: SuperFrom<T, M>,
impl<T, O, M> SuperInto<O, M> for Twhere
O: SuperFrom<T, M>,
Source§fn super_into(self) -> O
fn super_into(self) -> O
Source§impl<T> Tap for T
impl<T> Tap for T
Source§fn tap_borrow<B>(self, func: impl FnOnce(&B)) -> Self
fn tap_borrow<B>(self, func: impl FnOnce(&B)) -> Self
Borrow<B> of a value. Read moreSource§fn tap_borrow_mut<B>(self, func: impl FnOnce(&mut B)) -> Self
fn tap_borrow_mut<B>(self, func: impl FnOnce(&mut B)) -> Self
BorrowMut<B> of a value. Read moreSource§fn tap_ref<R>(self, func: impl FnOnce(&R)) -> Self
fn tap_ref<R>(self, func: impl FnOnce(&R)) -> Self
AsRef<R> view of a value. Read moreSource§fn tap_ref_mut<R>(self, func: impl FnOnce(&mut R)) -> Self
fn tap_ref_mut<R>(self, func: impl FnOnce(&mut R)) -> Self
AsMut<R> view of a value. Read moreSource§fn tap_deref<T>(self, func: impl FnOnce(&T)) -> Self
fn tap_deref<T>(self, func: impl FnOnce(&T)) -> Self
Deref::Target of a value. Read moreSource§fn tap_deref_mut<T>(self, func: impl FnOnce(&mut T)) -> Self
fn tap_deref_mut<T>(self, func: impl FnOnce(&mut T)) -> Self
Deref::Target of a value. Read moreSource§fn tap_dbg(self, func: impl FnOnce(&Self)) -> Self
fn tap_dbg(self, func: impl FnOnce(&Self)) -> Self
.tap() only in debug builds, and is erased in release builds.Source§fn tap_mut_dbg(self, func: impl FnOnce(&mut Self)) -> Self
fn tap_mut_dbg(self, func: impl FnOnce(&mut Self)) -> Self
.tap_mut() only in debug builds, and is erased in release
builds.Source§fn tap_borrow_dbg<B>(self, func: impl FnOnce(&B)) -> Self
fn tap_borrow_dbg<B>(self, func: impl FnOnce(&B)) -> Self
.tap_borrow() only in debug builds, and is erased in release
builds.Source§fn tap_borrow_mut_dbg<B>(self, func: impl FnOnce(&mut B)) -> Self
fn tap_borrow_mut_dbg<B>(self, func: impl FnOnce(&mut B)) -> Self
.tap_borrow_mut() only in debug builds, and is erased in release
builds.Source§fn tap_ref_dbg<R>(self, func: impl FnOnce(&R)) -> Self
fn tap_ref_dbg<R>(self, func: impl FnOnce(&R)) -> Self
.tap_ref() only in debug builds, and is erased in release
builds.Source§fn tap_ref_mut_dbg<R>(self, func: impl FnOnce(&mut R)) -> Self
fn tap_ref_mut_dbg<R>(self, func: impl FnOnce(&mut R)) -> Self
.tap_ref_mut() only in debug builds, and is erased in release
builds.Source§fn tap_deref_dbg<T>(self, func: impl FnOnce(&T)) -> Self
fn tap_deref_dbg<T>(self, func: impl FnOnce(&T)) -> Self
.tap_deref() only in debug builds, and is erased in release
builds.