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.










share|improve this question




























    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.










    share|improve this question


























      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.










      share|improve this question















      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






      share|improve this question















      share|improve this question













      share|improve this question




      share|improve this question








      edited Nov 8 at 18:07









      Shepmaster

      143k11268399




      143k11268399










      asked Nov 8 at 16:57









      Timmmm

      35.5k28189248




      35.5k28189248
























          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






          share|improve this answer






























            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.






            share|improve this answer























              Your Answer






              StackExchange.ifUsing("editor", function () {
              StackExchange.using("externalEditor", function () {
              StackExchange.using("snippets", function () {
              StackExchange.snippets.init();
              });
              });
              }, "code-snippets");

              StackExchange.ready(function() {
              var channelOptions = {
              tags: "".split(" "),
              id: "1"
              };
              initTagRenderer("".split(" "), "".split(" "), channelOptions);

              StackExchange.using("externalEditor", function() {
              // Have to fire editor after snippets, if snippets enabled
              if (StackExchange.settings.snippets.snippetsEnabled) {
              StackExchange.using("snippets", function() {
              createEditor();
              });
              }
              else {
              createEditor();
              }
              });

              function createEditor() {
              StackExchange.prepareEditor({
              heartbeatType: 'answer',
              convertImagesToLinks: true,
              noModals: true,
              showLowRepImageUploadWarning: true,
              reputationToPostImages: 10,
              bindNavPrevention: true,
              postfix: "",
              imageUploader: {
              brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
              contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
              allowUrls: true
              },
              onDemand: true,
              discardSelector: ".discard-answer"
              ,immediatelyShowMarkdownHelp:true
              });


              }
              });














               

              draft saved


              draft discarded


















              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

























              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






              share|improve this answer



























                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






                share|improve this answer

























                  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






                  share|improve this answer














                  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







                  share|improve this answer














                  share|improve this answer



                  share|improve this answer








                  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
























                      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.






                      share|improve this answer



























                        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.






                        share|improve this answer

























                          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.






                          share|improve this answer














                          Ah it has to be a Vec<P::Subpixel>, i.e. Vec<u8> rather than a Vec<Rgb<u8>>. That is a little annoying.







                          share|improve this answer














                          share|improve this answer



                          share|improve this answer








                          edited Nov 8 at 18:07









                          Shepmaster

                          143k11268399




                          143k11268399










                          answered Nov 8 at 17:18









                          Timmmm

                          35.5k28189248




                          35.5k28189248






























                               

                              draft saved


                              draft discarded



















































                               


                              draft saved


                              draft discarded














                              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





















































                              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







                              Popular posts from this blog

                              Schultheiß

                              Liste der Kulturdenkmale in Wilsdruff

                              Android Play Services Check