-
Notifications
You must be signed in to change notification settings - Fork 5
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #1 from photovoltex/trait-predefinition
Trait definitions
- Loading branch information
Showing
19 changed files
with
403 additions
and
196 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,2 +1,3 @@ | ||
.idea/ | ||
target/ | ||
dist/ |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,50 @@ | ||
use serde::{Serialize, Deserialize}; | ||
#[cfg(not(target_family = "wasm"))] | ||
use tauri::{AppHandle, Wry, Error}; | ||
|
||
/// traits for event emitting in the host code (feat: `tauri`) | ||
#[cfg(not(target_family = "wasm"))] | ||
pub mod emit; | ||
/// related generic struct and functions for autogenerated listen functions (target: `wasm` or feat: `wasm`) | ||
#[cfg(any(target_family = "wasm", feature = "wasm"))] | ||
pub mod listen; | ||
|
||
/// The trait which needs to be implemented for a [Field] | ||
/// | ||
/// Conditionally changes between [listen::Listen] and [emit::Emit] | ||
/// | ||
/// When compiled to "target_family = wasm" then following is true. | ||
/// ```ignore | ||
/// trait Parent = listen::Listen; | ||
/// ``` | ||
#[cfg(not(target_family = "wasm"))] | ||
pub trait Parent = emit::Emit; | ||
/// The trait which needs to be implemented for a [Field] | ||
/// | ||
/// Conditionally changes between [listen::Listen] and [emit::Emit] | ||
#[cfg(target_family = "wasm")] | ||
pub trait Parent = listen::Listen; | ||
|
||
/// Trait defining a [Field] to a related struct implementing [Parent] with the related [Field::Type] | ||
pub trait Field<P> | ||
where | ||
P: Parent, | ||
<Self as Field<P>>::Type: Clone + Serialize + for<'de> Deserialize<'de>, | ||
{ | ||
/// The type of the field | ||
type Type; | ||
|
||
#[cfg(any(target_family = "wasm", feature = "wasm"))] | ||
/// The event of the field | ||
const EVENT_NAME: &'static str; | ||
|
||
#[cfg(not(target_family = "wasm"))] | ||
/// Emits event of the related field with their value | ||
fn emit(parent: &P, handle: &AppHandle<Wry>) -> Result<(), Error>; | ||
|
||
#[cfg(not(target_family = "wasm"))] | ||
/// Updates the related field and emit its event | ||
/// | ||
/// Only required for "target_family = wasm" | ||
fn update(s: &mut P, handle: &AppHandle<Wry>, v: Self::Type) -> Result<(), Error>; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
use tauri::{AppHandle, Error, Wry}; | ||
|
||
use super::Field; | ||
|
||
/// Trait that defines the available event emitting methods | ||
pub trait Emit { | ||
/// Emit all field events | ||
fn emit_all(&self, handle: &AppHandle<Wry>) -> Result<(), Error>; | ||
|
||
/// Emit a single field event | ||
fn emit<F: Field<Self>>(&self, handle: &AppHandle<Wry>) -> Result<(), Error> | ||
where | ||
Self: Sized + Emit; | ||
|
||
/// Update a single field and emit it afterward | ||
fn update<F: Field<Self>>( | ||
&mut self, | ||
handle: &AppHandle<Wry>, | ||
field: F::Type, | ||
) -> Result<(), Error> | ||
where | ||
Self: Sized + Emit; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.