Lines Matching defs:T
28 /// `FileOps<T>` will always contain an `operations` which is safe to use for a file backed
29 /// off an inode which has a pointer to a `T` in its private data that is safe to convert
31 pub(super) struct FileOps<T> {
36 _phantom: PhantomData<T>,
39 impl<T> FileOps<T> {
43 /// inode has a pointer to `T` in its private data that is safe to convert into a reference.
60 impl<T: Adapter> FileOps<T> {
61 pub(super) const fn adapt(&self) -> &FileOps<T::Inner> {
62 // SAFETY: `Adapter` asserts that `T` can be legally cast to `T::Inner`.
68 impl<T> Deref for FileOps<T> {
76 struct WriterAdapter<T>(T);
78 impl<'a, T: Writer> fmt::Display for WriterAdapter<&'a T> {
88 /// * `inode`'s private pointer must point to a value of type `T` which will outlive the `inode`
91 unsafe extern "C" fn writer_open<T: Writer + Sync>(
101 // * The `data` pointer passed in the third argument is a valid `T` pointer that outlives
103 unsafe { bindings::single_open(file, Some(writer_act::<T>), data) }
110 /// `seq` must point to a live `seq_file` whose private data is a valid pointer to a `T` which may
112 unsafe extern "C" fn writer_act<T: Writer + Sync>(
116 // SAFETY: By caller precondition, this pointer is valid pointer to a `T`, and
118 let data = unsafe { &*((*seq).private.cast::<T>()) };
127 pub(crate) trait ReadFile<T> {
128 const FILE_OPS: FileOps<T>;
131 impl<T: Writer + Sync> ReadFile<T> for T {
132 const FILE_OPS: FileOps<T> = {
142 // inode's data pointer must point to a `T` that will outlive it, which matches the
148 fn read<T: Reader + Sync>(data: &T, buf: *const c_char, count: usize) -> isize {
162 /// `private` data in turn points to a `T` that implements `Reader`.
164 pub(crate) unsafe extern "C" fn write<T: Reader + Sync>(
172 // SAFETY: By caller precondition, this pointer is live and points to a value of type `T`.
173 let data = unsafe { &*(seq.private as *const T) };
178 pub(crate) trait ReadWriteFile<T> {
179 const FILE_OPS: FileOps<T>;
182 impl<T: Writer + Reader + Sync> ReadWriteFile<T> for T {
183 const FILE_OPS: FileOps<T> = {
185 open: Some(writer_open::<T>),
187 write: Some(write::<T>),
195 // the inode's data pointer must point to a `T` that will outlive it, which matches the
198 // which points to a `T` that will outlive it, which matches what `writer_open`
220 /// * The `private_data` of the file must contain a valid pointer to a `T` that implements
223 pub(crate) unsafe extern "C" fn write_only_write<T: Reader + Sync>(
230 // valid pointer to `T`.
231 let data = unsafe { &*((*file).private_data as *const T) };
235 pub(crate) trait WriteFile<T> {
236 const FILE_OPS: FileOps<T>;
239 impl<T: Reader + Sync> WriteFile<T> for T {
240 const FILE_OPS: FileOps<T> = {
243 write: Some(write_only_write::<T>),
250 // a `T` and be legal to convert to a shared reference, which `write_only_open`
256 extern "C" fn blob_read<T: BinaryWriter>(
264 // - The type invariant of `FileOps` guarantees that `private_data` points to a valid `T`.
265 let this = unsafe { &*((*file).private_data.cast::<T>()) };
287 pub(crate) trait BinaryReadFile<T> {
288 const FILE_OPS: FileOps<T>;
291 impl<T: BinaryWriter + Sync> BinaryReadFile<T> for T {
292 const FILE_OPS: FileOps<T> = {
294 read: Some(blob_read::<T>),
301 // - The private data of `struct inode` does always contain a pointer to a valid `T`.
304 // - `blob_read()` re-creates a reference to `T` from the `struct file`'s private data.
310 extern "C" fn blob_write<T: BinaryReader>(
318 // - The type invariant of `FileOps` guarantees that `private_data` points to a valid `T`.
319 let this = unsafe { &*((*file).private_data.cast::<T>()) };
341 pub(crate) trait BinaryWriteFile<T> {
342 const FILE_OPS: FileOps<T>;
345 impl<T: BinaryReader + Sync> BinaryWriteFile<T> for T {
346 const FILE_OPS: FileOps<T> = {
348 write: Some(blob_write::<T>),
355 // - The private data of `struct inode` does always contain a pointer to a valid `T`.
358 // - `blob_write()` re-creates a reference to `T` from the `struct file`'s private data.
365 pub(crate) trait BinaryReadWriteFile<T> {
366 const FILE_OPS: FileOps<T>;
369 impl<T: BinaryWriter + BinaryReader + Sync> BinaryReadWriteFile<T> for T {
370 const FILE_OPS: FileOps<T> = {
372 read: Some(blob_read::<T>),
373 write: Some(blob_write::<T>),
380 // - The private data of `struct inode` does always contain a pointer to a valid `T`.
383 // - `blob_read()` re-creates a reference to `T` from the `struct file`'s private data.
384 // - `blob_write()` re-creates a reference to `T` from the `struct file`'s private data.