I’m usually reading docs word-by-word, but not always understand it context, because beginner in C, Rust, and GTK at all. I’m web-dev, so it’s not always simple to understand after those trivial web-tech languages
Appends bytes to data that can be read from the input stream.
I don’t know how exactly it appends (create new Bytes inside or take the reference to the current data). If that’s pointer, it means that maybe reference counter increasing on C side and I can drop this Bytes pointer on complete without risk to lost the data referenced.
I’ve just created related subject on Rust forum about Bytes and GString pointers - because I still not sure that understand subject from documentation
even it’s shame, but maybe it’s better to ask than produce wrong implementations…
to be closer, some function read data from stream and track bytes downloaded. it includes callback function with Bytes until Bytes still in use. I can return reference or just clone.
pub fn read_all_from_socket_connection_async(
memory_input_stream: MemoryInputStream,
socket_connection: SocketConnection,
cancelable: Option<Cancellable>,
priority: Priority,
bytes_in_chunk: usize,
bytes_total_limit: usize,
bytes_total: usize,
on_chunk: impl Fn((Bytes, usize)) + 'static,
on_complete: impl FnOnce(Result<MemoryInputStream, (Error, Option<&str>)>) + 'static,
) {
socket_connection.input_stream().read_bytes_async(
bytes_in_chunk,
priority,
cancelable.clone().as_ref(),
move |result| match result {
Ok(bytes) => {
// Update bytes total
let bytes_total = bytes_total + bytes.len();
// Callback chunk function
on_chunk((bytes, bytes_total)); // need clone or just &ref
// some other deals with bytes..
// Write chunk bytes
memory_input_stream.add_bytes(&bytes);
doubts to use for on_chunk callback
on_chunk: impl Fn((Bytes, usize))
or
on_chunk: impl Fn((&Bytes, usize))
on_chunk function should return Bytes always (on every iteration), so stuck with that, even can simply return as &ref and forget about.