gtk4/auto/
password_entry_buffer.rs

1// This file was generated by gir (https://github.com/gtk-rs/gir)
2// from gir-files (https://github.com/gtk-rs/gir-files)
3// DO NOT EDIT
4
5use crate::{ffi, EntryBuffer};
6use glib::{prelude::*, translate::*};
7
8glib::wrapper! {
9    /// A [`EntryBuffer`][crate::EntryBuffer] that locks the underlying memory to prevent it
10    /// from being swapped to disk.
11    ///
12    /// [`PasswordEntry`][crate::PasswordEntry] uses a [`PasswordEntryBuffer`][crate::PasswordEntryBuffer].
13    ///
14    /// # Implements
15    ///
16    /// [`EntryBufferExt`][trait@crate::prelude::EntryBufferExt], [`trait@glib::ObjectExt`], [`EntryBufferExtManual`][trait@crate::prelude::EntryBufferExtManual]
17    #[doc(alias = "GtkPasswordEntryBuffer")]
18    pub struct PasswordEntryBuffer(Object<ffi::GtkPasswordEntryBuffer, ffi::GtkPasswordEntryBufferClass>) @extends EntryBuffer;
19
20    match fn {
21        type_ => || ffi::gtk_password_entry_buffer_get_type(),
22    }
23}
24
25impl PasswordEntryBuffer {
26    /// Creates a new [`EntryBuffer`][crate::EntryBuffer] using secure memory allocations.
27    ///
28    /// # Returns
29    ///
30    /// the newly created instance
31    #[doc(alias = "gtk_password_entry_buffer_new")]
32    pub fn new() -> PasswordEntryBuffer {
33        assert_initialized_main_thread!();
34        unsafe { EntryBuffer::from_glib_full(ffi::gtk_password_entry_buffer_new()).unsafe_cast() }
35    }
36
37    // rustdoc-stripper-ignore-next
38    /// Creates a new builder-pattern struct instance to construct [`PasswordEntryBuffer`] objects.
39    ///
40    /// This method returns an instance of [`PasswordEntryBufferBuilder`](crate::builders::PasswordEntryBufferBuilder) which can be used to create [`PasswordEntryBuffer`] objects.
41    pub fn builder() -> PasswordEntryBufferBuilder {
42        PasswordEntryBufferBuilder::new()
43    }
44}
45
46impl Default for PasswordEntryBuffer {
47    fn default() -> Self {
48        Self::new()
49    }
50}
51
52// rustdoc-stripper-ignore-next
53/// A [builder-pattern] type to construct [`PasswordEntryBuffer`] objects.
54///
55/// [builder-pattern]: https://doc.rust-lang.org/1.0.0/style/ownership/builders.html
56#[must_use = "The builder must be built to be used"]
57pub struct PasswordEntryBufferBuilder {
58    builder: glib::object::ObjectBuilder<'static, PasswordEntryBuffer>,
59}
60
61impl PasswordEntryBufferBuilder {
62    fn new() -> Self {
63        Self {
64            builder: glib::object::Object::builder(),
65        }
66    }
67
68    /// The maximum length (in characters) of the text in the buffer.
69    pub fn max_length(self, max_length: i32) -> Self {
70        Self {
71            builder: self.builder.property("max-length", max_length),
72        }
73    }
74
75    /// The contents of the buffer.
76    pub fn text(self, text: impl Into<glib::GString>) -> Self {
77        Self {
78            builder: self.builder.property("text", text.into()),
79        }
80    }
81
82    // rustdoc-stripper-ignore-next
83    /// Build the [`PasswordEntryBuffer`].
84    #[must_use = "Building the object from the builder is usually expensive and is not expected to have side effects"]
85    pub fn build(self) -> PasswordEntryBuffer {
86        assert_initialized_main_thread!();
87        self.builder.build()
88    }
89}