-
-
Notifications
You must be signed in to change notification settings - Fork 217
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Refactor
GodotString
, StringName
, and NodePath
, making them mor…
…e similar where they are the same. And placing them in their own module together. Add basic tests for `StringName` and `NodePath`. Add `Hash` impl using `InnerX::hash` for all, instead of just `StringName`. Add `new` constructors to all the string types. Add `as_inner` functions to all the string types. Add conversions between all the string types. Add pass-by-value conversions where there used to only be pass-by-reference conversions. Add `VariantMetadata` impl for `String`
- Loading branch information
Showing
13 changed files
with
488 additions
and
178 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
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,42 @@ | ||
/* | ||
* This Source Code Form is subject to the terms of the Mozilla Public | ||
* License, v. 2.0. If a copy of the MPL was not distributed with this | ||
* file, You can obtain one at https://mozilla.org/MPL/2.0/. | ||
*/ | ||
|
||
#![macro_use] | ||
|
||
macro_rules! impl_rust_string_conv { | ||
($Ty:ty) => { | ||
impl<S> From<S> for $Ty | ||
where | ||
S: AsRef<str>, | ||
{ | ||
fn from(string: S) -> Self { | ||
let intermediate = GodotString::from(string.as_ref()); | ||
Self::from(&intermediate) | ||
} | ||
} | ||
|
||
impl From<&$Ty> for String { | ||
fn from(string: &$Ty) -> Self { | ||
let intermediate = GodotString::from(string); | ||
Self::from(&intermediate) | ||
} | ||
} | ||
|
||
impl From<$Ty> for String { | ||
fn from(string: $Ty) -> Self { | ||
Self::from(&string) | ||
} | ||
} | ||
|
||
impl std::str::FromStr for $Ty { | ||
type Err = std::convert::Infallible; | ||
|
||
fn from_str(string: &str) -> Result<Self, Self::Err> { | ||
Ok(Self::from(string)) | ||
} | ||
} | ||
}; | ||
} |
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,44 @@ | ||
/* | ||
* This Source Code Form is subject to the terms of the Mozilla Public | ||
* License, v. 2.0. If a copy of the MPL was not distributed with this | ||
* file, You can obtain one at https://mozilla.org/MPL/2.0/. | ||
*/ | ||
|
||
//! Godot-types that are Strings. | ||
mod godot_string; | ||
mod macros; | ||
mod node_path; | ||
mod string_chars; | ||
mod string_name; | ||
|
||
use godot_ffi::VariantType; | ||
pub use godot_string::*; | ||
pub use node_path::*; | ||
pub use string_name::*; | ||
|
||
use super::{meta::VariantMetadata, FromVariant, ToVariant, Variant, VariantConversionError}; | ||
|
||
impl ToVariant for &str { | ||
fn to_variant(&self) -> Variant { | ||
GodotString::from(*self).to_variant() | ||
} | ||
} | ||
|
||
impl ToVariant for String { | ||
fn to_variant(&self) -> Variant { | ||
GodotString::from(self).to_variant() | ||
} | ||
} | ||
|
||
impl FromVariant for String { | ||
fn try_from_variant(variant: &Variant) -> Result<Self, VariantConversionError> { | ||
Ok(GodotString::try_from_variant(variant)?.to_string()) | ||
} | ||
} | ||
|
||
impl VariantMetadata for String { | ||
fn variant_type() -> VariantType { | ||
VariantType::String | ||
} | ||
} |
Oops, something went wrong.