field_lib

Cross-platform Rust runtime for Radroots iOS and Android apps
git clone https://radroots.dev/git/field_lib.git
Log | Files | Refs | README | LICENSE

builder.rs (1420B)


      1 use radroots_net_core::NetHandle;
      2 use radroots_net_core::builder::NetBuilder;
      3 use radroots_net_core::config::NetConfig;
      4 
      5 use crate::RadrootsAppError;
      6 
      7 pub struct RuntimeBuilder {
      8     config: NetConfig,
      9     manage_runtime: bool,
     10 }
     11 
     12 impl RuntimeBuilder {
     13     pub fn new() -> Self {
     14         Self {
     15             config: NetConfig::default(),
     16             manage_runtime: true,
     17         }
     18     }
     19 
     20     pub fn with_config(mut self, config: NetConfig) -> Self {
     21         self.config = config;
     22         self
     23     }
     24 
     25     pub fn manage_runtime(mut self, manage: bool) -> Self {
     26         self.manage_runtime = manage;
     27         self
     28     }
     29 
     30     pub fn build(self) -> Result<NetHandle, RadrootsAppError> {
     31         #[cfg(feature = "rt")]
     32         {
     33             match NetBuilder::new()
     34                 .config(self.config)
     35                 .manage_runtime(self.manage_runtime)
     36                 .build()
     37             {
     38                 Ok(handle) => Ok(handle),
     39                 Err(err) => Err(RadrootsAppError::initialization(format!(
     40                     "net build failed: {err}"
     41                 ))),
     42             }
     43         }
     44 
     45         #[cfg(not(feature = "rt"))]
     46         {
     47             let handle = NetBuilder::new()
     48                 .config(self.config)
     49                 .manage_runtime(self.manage_runtime)
     50                 .build()
     51                 .expect("net build must succeed when rt feature is disabled");
     52             Ok(handle)
     53         }
     54     }
     55 }