[ 
https://issues.apache.org/jira/browse/THRIFT-4147?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=15944528#comment-15944528
 ] 

ASF GitHub Bot commented on THRIFT-4147:
----------------------------------------

GitHub user sunchao opened a pull request:

    https://github.com/apache/thrift/pull/1226

    THRIFT-4147: Rust: protocol should accept transports with non-static …

    …lifetime

You can merge this pull request into a Git repository by running:

    $ git pull https://github.com/sunchao/thrift non-static-transport

Alternatively you can review and apply these changes as the patch at:

    https://github.com/apache/thrift/pull/1226.patch

To close this pull request, make a commit to your master/trunk branch
with (at least) the following in the commit message:

    This closes #1226
    
----
commit d250ad7ce51032f3087ccc3ff8a5141a7cd39a50
Author: Chao Sun <sunc...@apache.org>
Date:   2017-03-12T19:21:05Z

    THRIFT-4147: Rust: protocol should accept transports with non-static 
lifetime

----


> Rust: protocol should accept transports with non-static lifetime
> ----------------------------------------------------------------
>
>                 Key: THRIFT-4147
>                 URL: https://issues.apache.org/jira/browse/THRIFT-4147
>             Project: Thrift
>          Issue Type: Bug
>          Components: Rust - Library
>    Affects Versions: 1.0
>            Reporter: Chao Sun
>
> Currently for Rust language support, all protocols only accept 
> {{TTransport}}s with static lifetime. For instance:
> {code}
> impl TCompactInputProtocol {
>     /// Create a `TCompactInputProtocol` that reads bytes from `transport`.
>     pub fn new(transport: Rc<RefCell<Box<TTransport>>>) -> 
> TCompactInputProtocol {
>         TCompactInputProtocol {
>             last_read_field_id: 0,
>             read_field_id_stack: Vec::new(),
>             pending_read_bool_value: None,
>             transport: transport,
>         }
>     }
>    ...
> {code}
> This poses an issue when user has the following custom defined TTransport:
> {code}
> // A read buffer piggy-backed on T: Read. Write is not supported.
> pub struct ReadBuffer<'a, T> where T: 'a + Read {
>   data: &'a mut T
> }
> impl<'a, T: 'a + Read> ReadBuffer<'a, T> {
>   pub fn new(data: &'a mut T) -> Self { Self { data: data } }
> }
> impl<'a, T: 'a + Read> Read for ReadBuffer<'a, T> {
>   fn read(&mut self, buf: &mut [u8]) -> io::Result<usize> {
>     let bytes_read = self.data.read(buf)?;
>     Ok(bytes_read)
>   }
> }
> ...
> {code}
> It's better to change the protocols to accept {{Rc<RefCell<Box<TTransport + 
> 'a>>>}}



--
This message was sent by Atlassian JIRA
(v6.3.15#6346)

Reply via email to