1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
#![cfg(feature = "flexbuffers")]
use std::ops::Range;
use std::str::Utf8Error;

use crate::string::BufferString;
use crate::Buffer;

impl flexbuffers::Buffer for Buffer {
    type BufferString = BufferString;

    #[allow(clippy::same_name_method)]
    fn slice(&self, range: Range<usize>) -> Option<Self> {
        if range.end > self.len() || range.start >= self.len() || range.start >= range.end {
            return None;
        }
        Some(Buffer::slice(self, range))
    }

    fn empty() -> Self {
        Self::from_len_zeroed(0)
    }

    fn buffer_str(&self) -> Result<Self::BufferString, Utf8Error> {
        BufferString::try_from(self.clone())
    }
}