-
-
Notifications
You must be signed in to change notification settings - Fork 128
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
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.
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.
CStrV
because of std::ffi::CStr
. However I agree that name should be consistent with others gtk-rs types. I think also that CStrV
should be StrV
and StrV
should be StringV
or if you don't want breaking changes, maybe renameCStrV
to GStrV
and rename StrV
to GStringV
and create a type alias (deprecated) StrV = GStringV
.
Anyway let me know for CStrV
new name.
gio/src/subclass/vfs.rs
Outdated
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)
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.
done
gio/src/subclass/vfs.rs
Outdated
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
)?
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.
No it does not work. Calling File::for_path
is the only way to initialize GLocalVfs
.
Whatever, I have removed binding to existing (private) gio types and refactor the tests.
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.
I meant doing both the File::for_path()
and g_type_from_name()
inside the LazyLock
(or OnceCell
)
gio/src/subclass/vfs.rs
Outdated
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
?
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.
Just to be consistent with initialization way of other static variables in the gtk-rs. LazyLock
is not (yet) used in the project.
Whatever, I changed it.
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.
Also seems fine to me. I think I should go over the other code and update it one of these days :) Thanks for the reminder!
@@ -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]
).
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.
done
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)
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.
I tried to implement the same traits except Clone
and Drop
because CStrV
does not own the null-terminated array.
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]>
bcba69c
to
c333df3
Compare
Allow custom implementation of gio::Vfs