Upgrade to flutter_rust_bridge V2

This commit is contained in:
2024-02-06 20:19:53 +08:00
parent 55f5bac8d9
commit a6c9b46100
46 changed files with 2121 additions and 1213 deletions

1
rust/.gitignore vendored Normal file
View File

@ -0,0 +1 @@
/target

View File

@ -1,16 +1,15 @@
[package]
name = "rust"
name = "rust_lib"
version = "0.1.0"
edition = "2021"
[lib]
crate-type = ["staticlib", "cdylib"]
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
crate-type = ["cdylib", "staticlib"]
[dependencies]
flutter_rust_bridge = "1"
flutter_rust_bridge = "=2.0.0-dev.23"
http-downloader = { version = "0.3.2", features = ["status-tracker", "speed-tracker", "breakpoint-resume", "bson-file-archiver"] }
tokio = { version = "1", features = ["rt", "rt-multi-thread", "macros"] }
url = "2.4.1"
uuid = { version = "1.5.0", features = ["v4", "fast-rng", "macro-diagnostics"] }
url = "2.5.0"
uuid = { version = "1.7.0", features = ["v4", "fast-rng", "macro-diagnostics"] }
async-std = "1.12.0"

View File

@ -1,16 +1,11 @@
use std::sync::Arc;
use async_std::task;
use flutter_rust_bridge::StreamSink;
use crate::downloader::{do_cancel_download, do_start_download, DownloadCallbackData};
pub fn ping() -> String {
return String::from("PONG");
}
use crate::frb_generated::StreamSink;
pub fn start_download(url: String, save_path: String, file_name: String, connection_count: u8, sink: StreamSink<DownloadCallbackData>) {
let _ = do_start_download(url, save_path, file_name, connection_count, Arc::new(sink));
}
pub fn cancel_download(id: String) {
task::block_on(do_cancel_download(&id))
pub async fn cancel_download(id: String) {
do_cancel_download(&id).await
}

5
rust/src/api/mod.rs Normal file
View File

@ -0,0 +1,5 @@
//
// Do not put code in `mod.rs`, but put in e.g. `simple.rs`.
//
pub mod downloader_api;

View File

@ -1,83 +0,0 @@
use super::*;
// Section: wire functions
#[no_mangle]
pub extern "C" fn wire_ping(port_: i64) {
wire_ping_impl(port_)
}
#[no_mangle]
pub extern "C" fn wire_start_download(
port_: i64,
url: *mut wire_uint_8_list,
save_path: *mut wire_uint_8_list,
file_name: *mut wire_uint_8_list,
connection_count: u8,
) {
wire_start_download_impl(port_, url, save_path, file_name, connection_count)
}
#[no_mangle]
pub extern "C" fn wire_cancel_download(port_: i64, id: *mut wire_uint_8_list) {
wire_cancel_download_impl(port_, id)
}
// Section: allocate functions
#[no_mangle]
pub extern "C" fn new_uint_8_list_0(len: i32) -> *mut wire_uint_8_list {
let ans = wire_uint_8_list {
ptr: support::new_leak_vec_ptr(Default::default(), len),
len,
};
support::new_leak_box_ptr(ans)
}
// Section: related functions
// Section: impl Wire2Api
impl Wire2Api<String> for *mut wire_uint_8_list {
fn wire2api(self) -> String {
let vec: Vec<u8> = self.wire2api();
String::from_utf8_lossy(&vec).into_owned()
}
}
impl Wire2Api<Vec<u8>> for *mut wire_uint_8_list {
fn wire2api(self) -> Vec<u8> {
unsafe {
let wrap = support::box_from_leak_ptr(self);
support::vec_from_leak_ptr(wrap.ptr, wrap.len)
}
}
}
// Section: wire structs
#[repr(C)]
#[derive(Clone)]
pub struct wire_uint_8_list {
ptr: *mut u8,
len: i32,
}
// Section: impl NewWithNullPtr
pub trait NewWithNullPtr {
fn new_with_null_ptr() -> Self;
}
impl<T> NewWithNullPtr for *mut T {
fn new_with_null_ptr() -> Self {
std::ptr::null_mut()
}
}
// Section: sync execution mode utility
#[no_mangle]
pub extern "C" fn free_WireSyncReturn(ptr: support::WireSyncReturn) {
unsafe {
let _ = support::box_from_leak_ptr(ptr);
};
}

View File

@ -1,179 +0,0 @@
#![allow(
non_camel_case_types,
unused,
clippy::redundant_closure,
clippy::useless_conversion,
clippy::unit_arg,
clippy::double_parens,
non_snake_case,
clippy::too_many_arguments
)]
// AUTO GENERATED FILE, DO NOT EDIT.
// Generated by `flutter_rust_bridge`@ 1.82.3.
use crate::api::*;
use core::panic::UnwindSafe;
use flutter_rust_bridge::rust2dart::IntoIntoDart;
use flutter_rust_bridge::*;
use std::ffi::c_void;
use std::sync::Arc;
// Section: imports
use crate::downloader::DownloadCallbackData;
use crate::downloader::MyDownloaderStatus;
use crate::downloader::MyNetworkItemPendingType;
// Section: wire functions
fn wire_ping_impl(port_: MessagePort) {
FLUTTER_RUST_BRIDGE_HANDLER.wrap::<_, _, _, String, _>(
WrapInfo {
debug_name: "ping",
port: Some(port_),
mode: FfiCallMode::Normal,
},
move || move |task_callback| Result::<_, ()>::Ok(ping()),
)
}
fn wire_start_download_impl(
port_: MessagePort,
url: impl Wire2Api<String> + UnwindSafe,
save_path: impl Wire2Api<String> + UnwindSafe,
file_name: impl Wire2Api<String> + UnwindSafe,
connection_count: impl Wire2Api<u8> + UnwindSafe,
) {
FLUTTER_RUST_BRIDGE_HANDLER.wrap::<_, _, _, (), _>(
WrapInfo {
debug_name: "start_download",
port: Some(port_),
mode: FfiCallMode::Stream,
},
move || {
let api_url = url.wire2api();
let api_save_path = save_path.wire2api();
let api_file_name = file_name.wire2api();
let api_connection_count = connection_count.wire2api();
move |task_callback| {
Result::<_, ()>::Ok(start_download(
api_url,
api_save_path,
api_file_name,
api_connection_count,
task_callback.stream_sink::<_, DownloadCallbackData>(),
))
}
},
)
}
fn wire_cancel_download_impl(port_: MessagePort, id: impl Wire2Api<String> + UnwindSafe) {
FLUTTER_RUST_BRIDGE_HANDLER.wrap::<_, _, _, (), _>(
WrapInfo {
debug_name: "cancel_download",
port: Some(port_),
mode: FfiCallMode::Normal,
},
move || {
let api_id = id.wire2api();
move |task_callback| Result::<_, ()>::Ok(cancel_download(api_id))
},
)
}
// Section: wrapper structs
// Section: static checks
// Section: allocate functions
// Section: related functions
// Section: impl Wire2Api
pub trait Wire2Api<T> {
fn wire2api(self) -> T;
}
impl<T, S> Wire2Api<Option<T>> for *mut S
where
*mut S: Wire2Api<T>,
{
fn wire2api(self) -> Option<T> {
(!self.is_null()).then(|| self.wire2api())
}
}
impl Wire2Api<u8> for u8 {
fn wire2api(self) -> u8 {
self
}
}
// Section: impl IntoDart
impl support::IntoDart for DownloadCallbackData {
fn into_dart(self) -> support::DartAbi {
vec![
self.id.into_into_dart().into_dart(),
self.total.into_into_dart().into_dart(),
self.progress.into_into_dart().into_dart(),
self.speed.into_into_dart().into_dart(),
self.status.into_into_dart().into_dart(),
]
.into_dart()
}
}
impl support::IntoDartExceptPrimitive for DownloadCallbackData {}
impl rust2dart::IntoIntoDart<DownloadCallbackData> for DownloadCallbackData {
fn into_into_dart(self) -> Self {
self
}
}
impl support::IntoDart for MyDownloaderStatus {
fn into_dart(self) -> support::DartAbi {
match self {
Self::NoStart => vec![0.into_dart()],
Self::Running => vec![1.into_dart()],
Self::Pending(field0) => vec![2.into_dart(), field0.into_into_dart().into_dart()],
Self::Error(field0) => vec![3.into_dart(), field0.into_into_dart().into_dart()],
Self::Finished => vec![4.into_dart()],
}
.into_dart()
}
}
impl support::IntoDartExceptPrimitive for MyDownloaderStatus {}
impl rust2dart::IntoIntoDart<MyDownloaderStatus> for MyDownloaderStatus {
fn into_into_dart(self) -> Self {
self
}
}
impl support::IntoDart for MyNetworkItemPendingType {
fn into_dart(self) -> support::DartAbi {
match self {
Self::QueueUp => 0,
Self::Starting => 1,
Self::Stopping => 2,
Self::Initializing => 3,
}
.into_dart()
}
}
impl support::IntoDartExceptPrimitive for MyNetworkItemPendingType {}
impl rust2dart::IntoIntoDart<MyNetworkItemPendingType> for MyNetworkItemPendingType {
fn into_into_dart(self) -> Self {
self
}
}
// Section: executor
support::lazy_static! {
pub static ref FLUTTER_RUST_BRIDGE_HANDLER: support::DefaultHandler = Default::default();
}
#[cfg(not(target_family = "wasm"))]
#[path = "bridge_generated.io.rs"]
mod io;
#[cfg(not(target_family = "wasm"))]
pub use io::*;

View File

@ -5,11 +5,11 @@ use std::path::PathBuf;
use std::sync::Arc;
use std::time::Duration;
use async_std::sync::Mutex;
use flutter_rust_bridge::for_generated::lazy_static;
use http_downloader::{breakpoint_resume::DownloadBreakpointResumeExtension, ExtendedHttpFileDownloader, HttpDownloaderBuilder, speed_tracker::DownloadSpeedTrackerExtension, status_tracker::DownloadStatusTrackerExtension};
use http_downloader::bson_file_archiver::{ArchiveFilePath, BsonFileArchiverBuilder};
use url::Url;
use flutter_rust_bridge::StreamSink;
use flutter_rust_bridge::support::lazy_static;
use crate::frb_generated::StreamSink;
use http_downloader::status_tracker::{DownloaderStatus, NetworkItemPendingType};
use uuid::Uuid;
@ -107,7 +107,7 @@ pub async fn do_start_download(url: String, save_path: String, file_name: String
let total_len = total_size_future.await;
if let Some(total_len) = total_len {
// info!("Total size: {:.2} Mb",total_len.get() as f64 / 1024_f64/ 1024_f64);
sink_clone.add(DownloadCallbackData::new(id.to_string(), total_len.get()));
sink_clone.add(DownloadCallbackData::new(id.to_string(), total_len.get())).unwrap();
}
while downloaded_len_receiver.changed().await.is_ok() {
@ -122,7 +122,7 @@ pub async fn do_start_download(url: String, save_path: String, file_name: String
progress: p,
speed: _byte_per_second,
status: get_my_status(_status),
});
}).unwrap();
}
tokio::time::sleep(Duration::from_millis(100)).await;
}
@ -137,8 +137,7 @@ pub async fn do_start_download(url: String, save_path: String, file_name: String
progress: 0,
speed: 0,
status: get_my_status(_status),
});
sink.close();
}).unwrap();
remove_downloader(&id.to_string()).await;
println!("rust downloader download complete");
Ok(())

View File

@ -0,0 +1,13 @@
// This file is automatically generated, so please do not edit it.
// Generated by `flutter_rust_bridge`@ 2.0.0-dev.23.
// Section: imports
use super::*;
use flutter_rust_bridge::for_generated::byteorder::{NativeEndian, ReadBytesExt, WriteBytesExt};
use flutter_rust_bridge::for_generated::transform_result_dco;
use flutter_rust_bridge::{Handler, IntoIntoDart};
// Section: boilerplate
flutter_rust_bridge::frb_generated_boilerplate_io!();

459
rust/src/frb_generated.rs Normal file
View File

@ -0,0 +1,459 @@
// This file is automatically generated, so please do not edit it.
// Generated by `flutter_rust_bridge`@ 2.0.0-dev.23.
#![allow(
non_camel_case_types,
unused,
non_snake_case,
clippy::needless_return,
clippy::redundant_closure_call,
clippy::redundant_closure,
clippy::useless_conversion,
clippy::unit_arg,
clippy::unused_unit,
clippy::double_parens,
clippy::let_and_return,
clippy::too_many_arguments,
clippy::match_single_binding
)]
// Section: imports
use flutter_rust_bridge::for_generated::byteorder::{NativeEndian, ReadBytesExt, WriteBytesExt};
use flutter_rust_bridge::for_generated::transform_result_dco;
use flutter_rust_bridge::{Handler, IntoIntoDart};
// Section: boilerplate
flutter_rust_bridge::frb_generated_boilerplate!(
default_stream_sink_codec = SseCodec,
default_rust_opaque = RustOpaqueMoi,
default_rust_auto_opaque = RustAutoOpaqueMoi,
);
const FLUTTER_RUST_BRIDGE_CODEGEN_VERSION: &str = "2.0.0-dev.23";
// Section: executor
flutter_rust_bridge::frb_generated_default_handler!();
// Section: wire_funcs
fn wire_cancel_download_impl(
port_: flutter_rust_bridge::for_generated::MessagePort,
ptr_: flutter_rust_bridge::for_generated::PlatformGeneralizedUint8ListPtr,
rust_vec_len_: i32,
data_len_: i32,
) {
FLUTTER_RUST_BRIDGE_HANDLER.wrap_async::<flutter_rust_bridge::for_generated::SseCodec, _, _, _>(
flutter_rust_bridge::for_generated::TaskInfo {
debug_name: "cancel_download",
port: Some(port_),
mode: flutter_rust_bridge::for_generated::FfiCallMode::Normal,
},
move || {
let message = unsafe {
flutter_rust_bridge::for_generated::Dart2RustMessageSse::from_wire(
ptr_,
rust_vec_len_,
data_len_,
)
};
let mut deserializer =
flutter_rust_bridge::for_generated::SseDeserializer::new(message);
let api_id = <String>::sse_decode(&mut deserializer);
deserializer.end();
move |context| async move {
transform_result_sse(
(move || async move {
Result::<_, ()>::Ok(
crate::api::downloader_api::cancel_download(api_id).await,
)
})()
.await,
)
}
},
)
}
fn wire_start_download_impl(
port_: flutter_rust_bridge::for_generated::MessagePort,
ptr_: flutter_rust_bridge::for_generated::PlatformGeneralizedUint8ListPtr,
rust_vec_len_: i32,
data_len_: i32,
) {
FLUTTER_RUST_BRIDGE_HANDLER.wrap_normal::<flutter_rust_bridge::for_generated::SseCodec, _, _>(
flutter_rust_bridge::for_generated::TaskInfo {
debug_name: "start_download",
port: Some(port_),
mode: flutter_rust_bridge::for_generated::FfiCallMode::Stream,
},
move || {
let message = unsafe {
flutter_rust_bridge::for_generated::Dart2RustMessageSse::from_wire(
ptr_,
rust_vec_len_,
data_len_,
)
};
let mut deserializer =
flutter_rust_bridge::for_generated::SseDeserializer::new(message);
let api_url = <String>::sse_decode(&mut deserializer);
let api_save_path = <String>::sse_decode(&mut deserializer);
let api_file_name = <String>::sse_decode(&mut deserializer);
let api_connection_count = <u8>::sse_decode(&mut deserializer);
deserializer.end();
move |context| {
transform_result_sse((move || {
Result::<_, ()>::Ok(crate::api::downloader_api::start_download(
api_url,
api_save_path,
api_file_name,
api_connection_count,
StreamSink::new(
context
.rust2dart_context()
.stream_sink::<_, crate::downloader::DownloadCallbackData>(),
),
))
})())
}
},
)
}
// Section: dart2rust
impl SseDecode for String {
// Codec=Sse (Serialization based), see doc to use other codecs
fn sse_decode(deserializer: &mut flutter_rust_bridge::for_generated::SseDeserializer) -> Self {
let mut inner = <Vec<u8>>::sse_decode(deserializer);
return String::from_utf8(inner).unwrap();
}
}
impl SseDecode for crate::downloader::DownloadCallbackData {
// Codec=Sse (Serialization based), see doc to use other codecs
fn sse_decode(deserializer: &mut flutter_rust_bridge::for_generated::SseDeserializer) -> Self {
let mut var_id = <String>::sse_decode(deserializer);
let mut var_total = <u64>::sse_decode(deserializer);
let mut var_progress = <u64>::sse_decode(deserializer);
let mut var_speed = <u64>::sse_decode(deserializer);
let mut var_status = <crate::downloader::MyDownloaderStatus>::sse_decode(deserializer);
return crate::downloader::DownloadCallbackData {
id: var_id,
total: var_total,
progress: var_progress,
speed: var_speed,
status: var_status,
};
}
}
impl SseDecode for i32 {
// Codec=Sse (Serialization based), see doc to use other codecs
fn sse_decode(deserializer: &mut flutter_rust_bridge::for_generated::SseDeserializer) -> Self {
deserializer.cursor.read_i32::<NativeEndian>().unwrap()
}
}
impl SseDecode for Vec<u8> {
// Codec=Sse (Serialization based), see doc to use other codecs
fn sse_decode(deserializer: &mut flutter_rust_bridge::for_generated::SseDeserializer) -> Self {
let mut len_ = <i32>::sse_decode(deserializer);
let mut ans_ = vec![];
for idx_ in 0..len_ {
ans_.push(<u8>::sse_decode(deserializer));
}
return ans_;
}
}
impl SseDecode for crate::downloader::MyDownloaderStatus {
// Codec=Sse (Serialization based), see doc to use other codecs
fn sse_decode(deserializer: &mut flutter_rust_bridge::for_generated::SseDeserializer) -> Self {
let mut tag_ = <i32>::sse_decode(deserializer);
match tag_ {
0 => {
return crate::downloader::MyDownloaderStatus::NoStart;
}
1 => {
return crate::downloader::MyDownloaderStatus::Running;
}
2 => {
let mut var_field0 =
<crate::downloader::MyNetworkItemPendingType>::sse_decode(deserializer);
return crate::downloader::MyDownloaderStatus::Pending(var_field0);
}
3 => {
let mut var_field0 = <String>::sse_decode(deserializer);
return crate::downloader::MyDownloaderStatus::Error(var_field0);
}
4 => {
return crate::downloader::MyDownloaderStatus::Finished;
}
_ => {
unimplemented!("");
}
}
}
}
impl SseDecode for crate::downloader::MyNetworkItemPendingType {
// Codec=Sse (Serialization based), see doc to use other codecs
fn sse_decode(deserializer: &mut flutter_rust_bridge::for_generated::SseDeserializer) -> Self {
let mut inner = <i32>::sse_decode(deserializer);
return match inner {
0 => crate::downloader::MyNetworkItemPendingType::QueueUp,
1 => crate::downloader::MyNetworkItemPendingType::Starting,
2 => crate::downloader::MyNetworkItemPendingType::Stopping,
3 => crate::downloader::MyNetworkItemPendingType::Initializing,
_ => unreachable!("Invalid variant for MyNetworkItemPendingType: {}", inner),
};
}
}
impl SseDecode for u64 {
// Codec=Sse (Serialization based), see doc to use other codecs
fn sse_decode(deserializer: &mut flutter_rust_bridge::for_generated::SseDeserializer) -> Self {
deserializer.cursor.read_u64::<NativeEndian>().unwrap()
}
}
impl SseDecode for u8 {
// Codec=Sse (Serialization based), see doc to use other codecs
fn sse_decode(deserializer: &mut flutter_rust_bridge::for_generated::SseDeserializer) -> Self {
deserializer.cursor.read_u8().unwrap()
}
}
impl SseDecode for () {
// Codec=Sse (Serialization based), see doc to use other codecs
fn sse_decode(deserializer: &mut flutter_rust_bridge::for_generated::SseDeserializer) -> Self {}
}
impl SseDecode for bool {
// Codec=Sse (Serialization based), see doc to use other codecs
fn sse_decode(deserializer: &mut flutter_rust_bridge::for_generated::SseDeserializer) -> Self {
deserializer.cursor.read_u8().unwrap() != 0
}
}
fn pde_ffi_dispatcher_primary_impl(
func_id: i32,
port: flutter_rust_bridge::for_generated::MessagePort,
ptr: flutter_rust_bridge::for_generated::PlatformGeneralizedUint8ListPtr,
rust_vec_len: i32,
data_len: i32,
) {
// Codec=Pde (Serialization + dispatch), see doc to use other codecs
match func_id {
2 => wire_cancel_download_impl(port, ptr, rust_vec_len, data_len),
1 => wire_start_download_impl(port, ptr, rust_vec_len, data_len),
_ => unreachable!(),
}
}
fn pde_ffi_dispatcher_sync_impl(
func_id: i32,
ptr: flutter_rust_bridge::for_generated::PlatformGeneralizedUint8ListPtr,
rust_vec_len: i32,
data_len: i32,
) -> flutter_rust_bridge::for_generated::WireSyncRust2DartSse {
// Codec=Pde (Serialization + dispatch), see doc to use other codecs
match func_id {
_ => unreachable!(),
}
}
// Section: rust2dart
// Codec=Dco (DartCObject based), see doc to use other codecs
impl flutter_rust_bridge::IntoDart for crate::downloader::DownloadCallbackData {
fn into_dart(self) -> flutter_rust_bridge::for_generated::DartAbi {
[
self.id.into_into_dart().into_dart(),
self.total.into_into_dart().into_dart(),
self.progress.into_into_dart().into_dart(),
self.speed.into_into_dart().into_dart(),
self.status.into_into_dart().into_dart(),
]
.into_dart()
}
}
impl flutter_rust_bridge::for_generated::IntoDartExceptPrimitive
for crate::downloader::DownloadCallbackData
{
}
impl flutter_rust_bridge::IntoIntoDart<crate::downloader::DownloadCallbackData>
for crate::downloader::DownloadCallbackData
{
fn into_into_dart(self) -> crate::downloader::DownloadCallbackData {
self
}
}
// Codec=Dco (DartCObject based), see doc to use other codecs
impl flutter_rust_bridge::IntoDart for crate::downloader::MyDownloaderStatus {
fn into_dart(self) -> flutter_rust_bridge::for_generated::DartAbi {
match self {
crate::downloader::MyDownloaderStatus::NoStart => [0.into_dart()].into_dart(),
crate::downloader::MyDownloaderStatus::Running => [1.into_dart()].into_dart(),
crate::downloader::MyDownloaderStatus::Pending(field0) => {
[2.into_dart(), field0.into_into_dart().into_dart()].into_dart()
}
crate::downloader::MyDownloaderStatus::Error(field0) => {
[3.into_dart(), field0.into_into_dart().into_dart()].into_dart()
}
crate::downloader::MyDownloaderStatus::Finished => [4.into_dart()].into_dart(),
}
}
}
impl flutter_rust_bridge::for_generated::IntoDartExceptPrimitive
for crate::downloader::MyDownloaderStatus
{
}
impl flutter_rust_bridge::IntoIntoDart<crate::downloader::MyDownloaderStatus>
for crate::downloader::MyDownloaderStatus
{
fn into_into_dart(self) -> crate::downloader::MyDownloaderStatus {
self
}
}
// Codec=Dco (DartCObject based), see doc to use other codecs
impl flutter_rust_bridge::IntoDart for crate::downloader::MyNetworkItemPendingType {
fn into_dart(self) -> flutter_rust_bridge::for_generated::DartAbi {
match self {
Self::QueueUp => 0.into_dart(),
Self::Starting => 1.into_dart(),
Self::Stopping => 2.into_dart(),
Self::Initializing => 3.into_dart(),
}
}
}
impl flutter_rust_bridge::for_generated::IntoDartExceptPrimitive
for crate::downloader::MyNetworkItemPendingType
{
}
impl flutter_rust_bridge::IntoIntoDart<crate::downloader::MyNetworkItemPendingType>
for crate::downloader::MyNetworkItemPendingType
{
fn into_into_dart(self) -> crate::downloader::MyNetworkItemPendingType {
self
}
}
impl SseEncode for String {
// Codec=Sse (Serialization based), see doc to use other codecs
fn sse_encode(self, serializer: &mut flutter_rust_bridge::for_generated::SseSerializer) {
<Vec<u8>>::sse_encode(self.into_bytes(), serializer);
}
}
impl SseEncode for crate::downloader::DownloadCallbackData {
// Codec=Sse (Serialization based), see doc to use other codecs
fn sse_encode(self, serializer: &mut flutter_rust_bridge::for_generated::SseSerializer) {
<String>::sse_encode(self.id, serializer);
<u64>::sse_encode(self.total, serializer);
<u64>::sse_encode(self.progress, serializer);
<u64>::sse_encode(self.speed, serializer);
<crate::downloader::MyDownloaderStatus>::sse_encode(self.status, serializer);
}
}
impl SseEncode for i32 {
// Codec=Sse (Serialization based), see doc to use other codecs
fn sse_encode(self, serializer: &mut flutter_rust_bridge::for_generated::SseSerializer) {
serializer.cursor.write_i32::<NativeEndian>(self).unwrap();
}
}
impl SseEncode for Vec<u8> {
// Codec=Sse (Serialization based), see doc to use other codecs
fn sse_encode(self, serializer: &mut flutter_rust_bridge::for_generated::SseSerializer) {
<i32>::sse_encode(self.len() as _, serializer);
for item in self {
<u8>::sse_encode(item, serializer);
}
}
}
impl SseEncode for crate::downloader::MyDownloaderStatus {
// Codec=Sse (Serialization based), see doc to use other codecs
fn sse_encode(self, serializer: &mut flutter_rust_bridge::for_generated::SseSerializer) {
match self {
crate::downloader::MyDownloaderStatus::NoStart => {
<i32>::sse_encode(0, serializer);
}
crate::downloader::MyDownloaderStatus::Running => {
<i32>::sse_encode(1, serializer);
}
crate::downloader::MyDownloaderStatus::Pending(field0) => {
<i32>::sse_encode(2, serializer);
<crate::downloader::MyNetworkItemPendingType>::sse_encode(field0, serializer);
}
crate::downloader::MyDownloaderStatus::Error(field0) => {
<i32>::sse_encode(3, serializer);
<String>::sse_encode(field0, serializer);
}
crate::downloader::MyDownloaderStatus::Finished => {
<i32>::sse_encode(4, serializer);
}
}
}
}
impl SseEncode for crate::downloader::MyNetworkItemPendingType {
// Codec=Sse (Serialization based), see doc to use other codecs
fn sse_encode(self, serializer: &mut flutter_rust_bridge::for_generated::SseSerializer) {
<i32>::sse_encode(
match self {
crate::downloader::MyNetworkItemPendingType::QueueUp => 0,
crate::downloader::MyNetworkItemPendingType::Starting => 1,
crate::downloader::MyNetworkItemPendingType::Stopping => 2,
crate::downloader::MyNetworkItemPendingType::Initializing => 3,
_ => {
unimplemented!("");
}
},
serializer,
);
}
}
impl SseEncode for u64 {
// Codec=Sse (Serialization based), see doc to use other codecs
fn sse_encode(self, serializer: &mut flutter_rust_bridge::for_generated::SseSerializer) {
serializer.cursor.write_u64::<NativeEndian>(self).unwrap();
}
}
impl SseEncode for u8 {
// Codec=Sse (Serialization based), see doc to use other codecs
fn sse_encode(self, serializer: &mut flutter_rust_bridge::for_generated::SseSerializer) {
serializer.cursor.write_u8(self).unwrap();
}
}
impl SseEncode for () {
// Codec=Sse (Serialization based), see doc to use other codecs
fn sse_encode(self, serializer: &mut flutter_rust_bridge::for_generated::SseSerializer) {}
}
impl SseEncode for bool {
// Codec=Sse (Serialization based), see doc to use other codecs
fn sse_encode(self, serializer: &mut flutter_rust_bridge::for_generated::SseSerializer) {
serializer.cursor.write_u8(self as _).unwrap();
}
}
#[cfg(not(target_family = "wasm"))]
#[path = "frb_generated.io.rs"]
mod io;
#[cfg(not(target_family = "wasm"))]
pub use io::*;
/// cbindgen:ignore
#[cfg(target_family = "wasm")]
#[path = "frb_generated.web.rs"]
mod web;
#[cfg(target_family = "wasm")]
pub use web::*;

View File

@ -0,0 +1,15 @@
// This file is automatically generated, so please do not edit it.
// Generated by `flutter_rust_bridge`@ 2.0.0-dev.23.
// Section: imports
use super::*;
use flutter_rust_bridge::for_generated::byteorder::{NativeEndian, ReadBytesExt, WriteBytesExt};
use flutter_rust_bridge::for_generated::transform_result_dco;
use flutter_rust_bridge::for_generated::wasm_bindgen;
use flutter_rust_bridge::for_generated::wasm_bindgen::prelude::*;
use flutter_rust_bridge::{Handler, IntoIntoDart};
// Section: boilerplate
flutter_rust_bridge::frb_generated_boilerplate_web!();

View File

@ -1,3 +1,3 @@
mod frb_generated;
mod api;
mod bridge_generated;
mod downloader;