function or associated item not found for image::ImageBuffer::from_vec()
up vote
0
down vote
favorite
I'm using Piston's image
crate, with this code:
use image::{Rgb, ImageBuffer, Pixel};
let image = Vec::<Rgb<u8>>::new();
let image_buffer = ImageBuffer::<Rgb<u8>, Vec<Rgb<u8>>>::from_vec(
width, height
image,
).unwrap();
However I get this error:
error[E0599]: no function or associated item named `from_vec` found for type `image::ImageBuffer<image::Rgb<u8>, std::vec::Vec<image::Rgb<u8>>>` in the current scope
--> src/main.rs:348:21
|
348 | let image_buffer = ImageBuffer::<Rgb<u8>, Vec<Rgb<u8>>>::from_vec(
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ function or associated item not found in `image::ImageBuffer<image::Rgb<u8>, std::vec::Vec<image::Rgb<u8>>>`
I can't work out why. It's clearly in the documentation, and the types seem right as far as I can tell.
image rust rust-piston
add a comment |
up vote
0
down vote
favorite
I'm using Piston's image
crate, with this code:
use image::{Rgb, ImageBuffer, Pixel};
let image = Vec::<Rgb<u8>>::new();
let image_buffer = ImageBuffer::<Rgb<u8>, Vec<Rgb<u8>>>::from_vec(
width, height
image,
).unwrap();
However I get this error:
error[E0599]: no function or associated item named `from_vec` found for type `image::ImageBuffer<image::Rgb<u8>, std::vec::Vec<image::Rgb<u8>>>` in the current scope
--> src/main.rs:348:21
|
348 | let image_buffer = ImageBuffer::<Rgb<u8>, Vec<Rgb<u8>>>::from_vec(
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ function or associated item not found in `image::ImageBuffer<image::Rgb<u8>, std::vec::Vec<image::Rgb<u8>>>`
I can't work out why. It's clearly in the documentation, and the types seem right as far as I can tell.
image rust rust-piston
add a comment |
up vote
0
down vote
favorite
up vote
0
down vote
favorite
I'm using Piston's image
crate, with this code:
use image::{Rgb, ImageBuffer, Pixel};
let image = Vec::<Rgb<u8>>::new();
let image_buffer = ImageBuffer::<Rgb<u8>, Vec<Rgb<u8>>>::from_vec(
width, height
image,
).unwrap();
However I get this error:
error[E0599]: no function or associated item named `from_vec` found for type `image::ImageBuffer<image::Rgb<u8>, std::vec::Vec<image::Rgb<u8>>>` in the current scope
--> src/main.rs:348:21
|
348 | let image_buffer = ImageBuffer::<Rgb<u8>, Vec<Rgb<u8>>>::from_vec(
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ function or associated item not found in `image::ImageBuffer<image::Rgb<u8>, std::vec::Vec<image::Rgb<u8>>>`
I can't work out why. It's clearly in the documentation, and the types seem right as far as I can tell.
image rust rust-piston
I'm using Piston's image
crate, with this code:
use image::{Rgb, ImageBuffer, Pixel};
let image = Vec::<Rgb<u8>>::new();
let image_buffer = ImageBuffer::<Rgb<u8>, Vec<Rgb<u8>>>::from_vec(
width, height
image,
).unwrap();
However I get this error:
error[E0599]: no function or associated item named `from_vec` found for type `image::ImageBuffer<image::Rgb<u8>, std::vec::Vec<image::Rgb<u8>>>` in the current scope
--> src/main.rs:348:21
|
348 | let image_buffer = ImageBuffer::<Rgb<u8>, Vec<Rgb<u8>>>::from_vec(
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ function or associated item not found in `image::ImageBuffer<image::Rgb<u8>, std::vec::Vec<image::Rgb<u8>>>`
I can't work out why. It's clearly in the documentation, and the types seem right as far as I can tell.
image rust rust-piston
image rust rust-piston
edited Nov 8 at 18:07
Shepmaster
143k11268399
143k11268399
asked Nov 8 at 16:57
Timmmm
35.5k28189248
35.5k28189248
add a comment |
add a comment |
2 Answers
2
active
oldest
votes
up vote
2
down vote
accepted
Expanding a bit: In the example above, we have a ImageBuffer::<Rgb<u8>, Vec<Rgb<u8>>
. And ImageBuffer
provides two implementations of from_vec
, depending on its type parameters:
impl<P, Container> ImageBuffer<P, Container>
where
P: Pixel<Subpixel = u8> + 'static,
Container: Deref<Target = [u8]>,
impl<P: Pixel + 'static> ImageBuffer<P, Vec<P::Subpixel>>
where
P::Subpixel: 'static,
Neither of these worked here because the Container
parameter type in ImageBuffer<Rgb<u8>, Vec<Rgb<u8>>
is a vector of Rgb<u8>
values. It will dereference to a slice of [Rgb<u8>]
, making it incompatible with the first implementation, and the second one expects a vector of subpixel values (<P as Pixel>::Subpixel
) rather than actual pixel values (Rgb<u8>
). This is generally what the ImageBuffer
type in this crate expects as its pixel data container.
Working example:
extern crate image;
use image::{ImageBuffer, Pixel, Rgb};
fn main() {
let width = 64;
let height = 64;
let image = vec![0x7F_u8; width as usize * height as usize * 3];
let image_buffer =
ImageBuffer::<Rgb<u8>, Vec<u8>>::from_vec(width, height, image).unwrap();
}
Playground
add a comment |
up vote
0
down vote
Ah it has to be a Vec<P::Subpixel>
, i.e. Vec<u8>
rather than a Vec<Rgb<u8>>
. That is a little annoying.
add a comment |
2 Answers
2
active
oldest
votes
2 Answers
2
active
oldest
votes
active
oldest
votes
active
oldest
votes
up vote
2
down vote
accepted
Expanding a bit: In the example above, we have a ImageBuffer::<Rgb<u8>, Vec<Rgb<u8>>
. And ImageBuffer
provides two implementations of from_vec
, depending on its type parameters:
impl<P, Container> ImageBuffer<P, Container>
where
P: Pixel<Subpixel = u8> + 'static,
Container: Deref<Target = [u8]>,
impl<P: Pixel + 'static> ImageBuffer<P, Vec<P::Subpixel>>
where
P::Subpixel: 'static,
Neither of these worked here because the Container
parameter type in ImageBuffer<Rgb<u8>, Vec<Rgb<u8>>
is a vector of Rgb<u8>
values. It will dereference to a slice of [Rgb<u8>]
, making it incompatible with the first implementation, and the second one expects a vector of subpixel values (<P as Pixel>::Subpixel
) rather than actual pixel values (Rgb<u8>
). This is generally what the ImageBuffer
type in this crate expects as its pixel data container.
Working example:
extern crate image;
use image::{ImageBuffer, Pixel, Rgb};
fn main() {
let width = 64;
let height = 64;
let image = vec![0x7F_u8; width as usize * height as usize * 3];
let image_buffer =
ImageBuffer::<Rgb<u8>, Vec<u8>>::from_vec(width, height, image).unwrap();
}
Playground
add a comment |
up vote
2
down vote
accepted
Expanding a bit: In the example above, we have a ImageBuffer::<Rgb<u8>, Vec<Rgb<u8>>
. And ImageBuffer
provides two implementations of from_vec
, depending on its type parameters:
impl<P, Container> ImageBuffer<P, Container>
where
P: Pixel<Subpixel = u8> + 'static,
Container: Deref<Target = [u8]>,
impl<P: Pixel + 'static> ImageBuffer<P, Vec<P::Subpixel>>
where
P::Subpixel: 'static,
Neither of these worked here because the Container
parameter type in ImageBuffer<Rgb<u8>, Vec<Rgb<u8>>
is a vector of Rgb<u8>
values. It will dereference to a slice of [Rgb<u8>]
, making it incompatible with the first implementation, and the second one expects a vector of subpixel values (<P as Pixel>::Subpixel
) rather than actual pixel values (Rgb<u8>
). This is generally what the ImageBuffer
type in this crate expects as its pixel data container.
Working example:
extern crate image;
use image::{ImageBuffer, Pixel, Rgb};
fn main() {
let width = 64;
let height = 64;
let image = vec![0x7F_u8; width as usize * height as usize * 3];
let image_buffer =
ImageBuffer::<Rgb<u8>, Vec<u8>>::from_vec(width, height, image).unwrap();
}
Playground
add a comment |
up vote
2
down vote
accepted
up vote
2
down vote
accepted
Expanding a bit: In the example above, we have a ImageBuffer::<Rgb<u8>, Vec<Rgb<u8>>
. And ImageBuffer
provides two implementations of from_vec
, depending on its type parameters:
impl<P, Container> ImageBuffer<P, Container>
where
P: Pixel<Subpixel = u8> + 'static,
Container: Deref<Target = [u8]>,
impl<P: Pixel + 'static> ImageBuffer<P, Vec<P::Subpixel>>
where
P::Subpixel: 'static,
Neither of these worked here because the Container
parameter type in ImageBuffer<Rgb<u8>, Vec<Rgb<u8>>
is a vector of Rgb<u8>
values. It will dereference to a slice of [Rgb<u8>]
, making it incompatible with the first implementation, and the second one expects a vector of subpixel values (<P as Pixel>::Subpixel
) rather than actual pixel values (Rgb<u8>
). This is generally what the ImageBuffer
type in this crate expects as its pixel data container.
Working example:
extern crate image;
use image::{ImageBuffer, Pixel, Rgb};
fn main() {
let width = 64;
let height = 64;
let image = vec![0x7F_u8; width as usize * height as usize * 3];
let image_buffer =
ImageBuffer::<Rgb<u8>, Vec<u8>>::from_vec(width, height, image).unwrap();
}
Playground
Expanding a bit: In the example above, we have a ImageBuffer::<Rgb<u8>, Vec<Rgb<u8>>
. And ImageBuffer
provides two implementations of from_vec
, depending on its type parameters:
impl<P, Container> ImageBuffer<P, Container>
where
P: Pixel<Subpixel = u8> + 'static,
Container: Deref<Target = [u8]>,
impl<P: Pixel + 'static> ImageBuffer<P, Vec<P::Subpixel>>
where
P::Subpixel: 'static,
Neither of these worked here because the Container
parameter type in ImageBuffer<Rgb<u8>, Vec<Rgb<u8>>
is a vector of Rgb<u8>
values. It will dereference to a slice of [Rgb<u8>]
, making it incompatible with the first implementation, and the second one expects a vector of subpixel values (<P as Pixel>::Subpixel
) rather than actual pixel values (Rgb<u8>
). This is generally what the ImageBuffer
type in this crate expects as its pixel data container.
Working example:
extern crate image;
use image::{ImageBuffer, Pixel, Rgb};
fn main() {
let width = 64;
let height = 64;
let image = vec![0x7F_u8; width as usize * height as usize * 3];
let image_buffer =
ImageBuffer::<Rgb<u8>, Vec<u8>>::from_vec(width, height, image).unwrap();
}
Playground
edited Nov 8 at 18:07
Shepmaster
143k11268399
143k11268399
answered Nov 8 at 17:30
E_net4 is kind and welcoming
11.2k63468
11.2k63468
add a comment |
add a comment |
up vote
0
down vote
Ah it has to be a Vec<P::Subpixel>
, i.e. Vec<u8>
rather than a Vec<Rgb<u8>>
. That is a little annoying.
add a comment |
up vote
0
down vote
Ah it has to be a Vec<P::Subpixel>
, i.e. Vec<u8>
rather than a Vec<Rgb<u8>>
. That is a little annoying.
add a comment |
up vote
0
down vote
up vote
0
down vote
Ah it has to be a Vec<P::Subpixel>
, i.e. Vec<u8>
rather than a Vec<Rgb<u8>>
. That is a little annoying.
Ah it has to be a Vec<P::Subpixel>
, i.e. Vec<u8>
rather than a Vec<Rgb<u8>>
. That is a little annoying.
edited Nov 8 at 18:07
Shepmaster
143k11268399
143k11268399
answered Nov 8 at 17:18
Timmmm
35.5k28189248
35.5k28189248
add a comment |
add a comment |
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53212611%2ffunction-or-associated-item-not-found-for-imageimagebufferfrom-vec%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown