Uploaded image for project: 'Thrift'
  1. Thrift
  2. THRIFT-4147

Rust: protocol should accept transports with non-static lifetime

    XMLWordPrintableJSON

    Details

    • Type: Bug
    • Status: Closed
    • Priority: Major
    • Resolution: Fixed
    • Affects Version/s: None
    • Fix Version/s: 0.11.0
    • Component/s: Rust - Library
    • Labels:
      None

      Description

      Currently for Rust language support, all protocols only accept {{TTransport}}s with static lifetime. For instance:

      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,
              }
          }
         ...
      

      This poses an issue when user has the following custom defined TTransport:

      // 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)
        }
      }
      ...
      

      It's better to change the protocols to accept Rc<RefCell<Box<TTransport + 'a>>>

        Attachments

          Issue Links

            Activity

              People

              • Assignee:
                jking3 James E. King III
                Reporter:
                csun Chao Sun
              • Votes:
                0 Vote for this issue
                Watchers:
                3 Start watching this issue

                Dates

                • Created:
                  Updated:
                  Resolved: