-
-
Notifications
You must be signed in to change notification settings - Fork 126
Add gio::Vfs subclass #1726
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Add gio::Vfs subclass #1726
Conversation
63b4266
to
6427fa2
Compare
2484ba8
to
8a65537
Compare
Looks good to me except for the two open discussions about the string array. |
8a65537
to
ea7130d
Compare
ea7130d
to
b831e69
Compare
b831e69
to
056b4a5
Compare
This type represents a borrowed reference to a `NULL`-terminated array of `NULL`-terminated UTF-8 strings. Signed-off-by: fbrouille <[email protected]>
Signed-off-by: fbrouille <[email protected]>
056b4a5
to
bcba69c
Compare
/// It can be constructed safely from a `&StrV` and unsafely from a pointer to a C array. | ||
/// This type is very similar to `[GStringPtr]`, but with one added constraint: the underlying C array must be `NULL`-terminated. | ||
#[repr(transparent)] | ||
pub struct CStrV { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The name seems inconsistent with everything else. This is basically the String
/PathBuf
(StrV
) vs. str
/Path
(CStrV
) duality. Maybe this one should've actually been StrV
and the other one StringV
. Using Buf
here seems wrong.
In other places (e.g. in gstreamer
) there's a pattern of Foo
and FooRef
, so maybe we can just call this one StrVRef
? @bilelmoussaoui what do you think?
Also GStringPtr
is an ugly name, should probably reconsider that before the next release. Its difference with GStr
is that it doesn't store the length and is equivalent with the raw C pointer. GStrLite
or so... doesn't have to be solved as part of this PR but in case someone has ideas while we talk about naming anyway.
self.parent_get_file_for_uri(uri) | ||
} | ||
|
||
unsafe fn get_supported_uri_schemes(&self) -> &'static CStrV { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
unsafe fn get_supported_uri_schemes(&self) -> &'static CStrV { | |
fn get_supported_uri_schemes(&self) -> &'static CStrV { |
no need to for this to be unsafe anymore (but also if it was necessary then the trait impl would have to be unsafe: unsafe trait is unsafe to implement, unsafe trait function is unsafe to call)
let _ = File::for_path("path"); | ||
}); | ||
glib::gobject_ffi::g_type_from_name("GLocalVfs".to_glib_none().0) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Not that it really matters because this is a test, but why not call g_type_from_name()
also inside the Once
(and make it a LazyLock
)?
static SUPPORTED_URI_SCHEMES: std::sync::OnceLock<glib::StrV> = | ||
std::sync::OnceLock::new(); | ||
SUPPORTED_URI_SCHEMES | ||
.get_or_init(|| glib::StrV::from(["myvfs"])) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why not LazyLock
?
@@ -123,6 +123,20 @@ impl std::ops::Deref for StrV { | |||
} | |||
} | |||
|
|||
impl AsRef<CStrV> for StrV { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Should probably also Deref
into &CStrV
(which in turn Deref
into &[GStringPtr]
).
inner: [GStringPtr], | ||
} | ||
|
||
impl CStrV { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Should probably get all the same trait impls that StrV
has (PartialEq
, etc)
Allow custom implementation of gio::Vfs