title: Is it possible to create a Stream from a File rather than loading the file contents into memory?
body: <p>I'm currently using the <code>rusoto_s3</code> lib to upload a file to S3. All the examples I have found do the same thing: Open a file, read the full contents of the file into memory (<code>Vec&lt;u8&gt;</code>), then convert the Vec into a <code>ByteStream</code> (which implements <code>From&lt;Vec&lt;u8&gt;&gt;</code>). Here is a code example:</p>
  
  <pre><code>fn upload_file(&amp;self, file_path: &amp;Path) -&gt; FileResult&lt;PutObjectOutput&gt; {
      let mut file = File::open(file_path)?;
      let mut file_data: Vec&lt;u8&gt; = vec![];
      file.read_to_end(&amp;mut file_data)?;
  
      let client = S3Client::new(Region::UsEast1);
      let mut request = PutObjectRequest::default();
      request.body = Some(file_data.into());
  
      Ok(client.put_object(request).sync()?)
  }
  </code></pre>
  
  <p>This is probably acceptable for small files, but (I assume) this technique would break down as soon as you attempt to upload a file with a size greater than the available heap memory.</p>
  
  <p>Another way to create a <code>ByteStream</code> is by <a href="https://rusoto.github.io/rusoto/rusoto_core/struct.ByteStream.html#method.new" rel="noreferrer">using this initializer</a> which accepts an object implementing the <code>Stream</code> trait. I would assume that <code>File</code> would implement this trait, but this does not appear to be the case. </p>
  
  <h3>My question(s):</h3>
  
  <p>Is there some type which can be constructed from a <code>File</code> which implements <code>Stream</code>? Is the correct solution to make my own tuple struct which wraps <code>File</code> and implements <code>Stream</code> itself, and is this implementation trivial? Is there another solution I'm not seeing, or am I simply misunderstanding how memory is allocated in the code above?</p>