mod gstring;
mod macros;
mod node_path;
mod string_macros;
mod string_name;
pub use gstring::{ExFind as GStringExFind, ExSplit as GStringExSplit, *};
pub use node_path::NodePath;
pub use string_name::{ExFind as StringNameExFind, ExSplit as StringNameExSplit, *};
use crate::meta;
use crate::meta::error::ConvertError;
use crate::meta::shape::GodotShape;
use crate::meta::{FromGodot, GodotConvert, ToGodot};
impl GodotConvert for &str {
type Via = GString;
fn godot_shape() -> GodotShape {
GString::godot_shape()
}
}
impl ToGodot for &str {
type Pass = meta::ByValue;
fn to_godot(&self) -> Self::Via {
GString::from(*self)
}
}
impl GodotConvert for String {
type Via = GString;
fn godot_shape() -> GodotShape {
GString::godot_shape()
}
}
impl ToGodot for String {
type Pass = meta::ByValue;
fn to_godot(&self) -> Self::Via {
GString::from(self)
}
}
impl FromGodot for String {
fn try_from_godot(via: Self::Via) -> Result<Self, ConvertError> {
Ok(via.to_string())
}
}
#[non_exhaustive]
#[derive(Copy, Clone, Eq, PartialEq, Debug)]
pub enum Encoding {
Ascii,
Latin1,
Utf8,
}
fn populated_or_none(s: GString) -> Option<GString> {
if s.is_empty() { None } else { Some(s) }
}
use standard_fmt::pad_if_needed;
mod standard_fmt {
use std::fmt;
use std::fmt::Write;
pub fn pad_if_needed<F>(f: &mut fmt::Formatter<'_>, display_impl: F) -> fmt::Result
where
F: Fn(&mut fmt::Formatter<'_>) -> fmt::Result,
{
let needs_format = f.width().is_some() || f.precision().is_some() || f.align().is_some();
if !needs_format {
return display_impl(f);
}
let ic = FmtInterceptor { display_impl };
let mut local_str = String::new();
write!(&mut local_str, "{ic}")?;
f.pad(&local_str)
}
struct FmtInterceptor<F>
where
F: Fn(&mut fmt::Formatter<'_>) -> fmt::Result,
{
display_impl: F,
}
impl<F> fmt::Display for FmtInterceptor<F>
where
F: Fn(&mut fmt::Formatter<'_>) -> fmt::Result,
{
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
(self.display_impl)(f)
}
}
}