Skip to content

Commit 037dbe4

Browse files
committed
docs: enforce doc comments for ext-php-rs
Refs: #392
1 parent 682ba1b commit 037dbe4

File tree

16 files changed

+218
-13
lines changed

16 files changed

+218
-13
lines changed

Cargo.toml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,9 @@ members = [
5050
[package.metadata.docs.rs]
5151
rustdoc-args = ["--cfg", "docs"]
5252

53+
[lints.rust]
54+
missing_docs = "warn"
55+
5356
[[example]]
5457
name = "hello_world"
5558
crate-type = ["cdylib"]

src/constant.rs

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -40,11 +40,7 @@ pub trait IntoConst: Debug {
4040
/// }
4141
/// ```
4242
fn register_constant(&self, name: &str, module_number: i32) -> Result<()> {
43-
self.register_constant_flags(
44-
name,
45-
module_number,
46-
GlobalConstantFlags::CaseSensitive | GlobalConstantFlags::Persistent,
47-
)
43+
self.register_constant_flags(name, module_number, GlobalConstantFlags::Persistent)
4844
}
4945

5046
/// Registers a global module constant in PHP, with the value as the content

src/describe/abi.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -129,7 +129,9 @@ impl Display for RString {
129129
/// An ABI-stable [`Option`][std::option::Option].
130130
#[repr(C, u8)]
131131
pub enum Option<T> {
132+
/// [`Option::Some`][std::option::Option::Some] variant.
132133
Some(T),
134+
/// [`Option::None`][std::option::Option::None] variant.
133135
None,
134136
}
135137

src/flags.rs

Lines changed: 134 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,32 +34,57 @@ bitflags! {
3434
/// Flags used for setting the type of Zval.
3535
#[derive(PartialEq, Eq, PartialOrd, Ord, Hash, Debug, Clone, Copy)]
3636
pub struct ZvalTypeFlags: u32 {
37+
/// Undefined
3738
const Undef = IS_UNDEF;
39+
/// Null
3840
const Null = IS_NULL;
41+
/// `false`
3942
const False = IS_FALSE;
43+
/// `true`
4044
const True = IS_TRUE;
45+
/// Integer
4146
const Long = IS_LONG;
47+
/// Floating point number
4248
const Double = IS_DOUBLE;
49+
/// String
4350
const String = IS_STRING;
51+
/// Array
4452
const Array = IS_ARRAY;
53+
/// Object
4554
const Object = IS_OBJECT;
55+
/// Resource
4656
const Resource = IS_RESOURCE;
57+
/// Reference
4758
const Reference = IS_REFERENCE;
59+
/// Callable
4860
const Callable = IS_CALLABLE;
61+
/// Constant expression
4962
const ConstantExpression = IS_CONSTANT_AST;
63+
/// Void
5064
const Void = IS_VOID;
65+
/// Pointer
5166
const Ptr = IS_PTR;
67+
/// Iterable
5268
const Iterable = IS_ITERABLE;
5369

70+
/// Interned string extended
5471
const InternedStringEx = Self::String.bits();
72+
/// String extended
5573
const StringEx = Self::String.bits() | Self::RefCounted.bits();
74+
/// Array extended
5675
const ArrayEx = Self::Array.bits() | Self::RefCounted.bits() | Self::Collectable.bits();
76+
/// Object extended
5777
const ObjectEx = Self::Object.bits() | Self::RefCounted.bits() | Self::Collectable.bits();
78+
/// Resource extended
5879
const ResourceEx = Self::Resource.bits() | Self::RefCounted.bits();
80+
/// Reference extended
5981
const ReferenceEx = Self::Reference.bits() | Self::RefCounted.bits();
82+
/// Constant ast extended
6083
const ConstantAstEx = Self::ConstantExpression.bits() | Self::RefCounted.bits();
6184

85+
/// Reference counted
6286
const RefCounted = (IS_TYPE_REFCOUNTED << Z_TYPE_FLAGS_SHIFT);
87+
/// Collectable
6388
const Collectable = (IS_TYPE_COLLECTABLE << Z_TYPE_FLAGS_SHIFT);
6489
}
6590
}
@@ -68,29 +93,52 @@ bitflags! {
6893
/// Flags for building classes.
6994
#[derive(PartialEq, Eq, PartialOrd, Ord, Hash, Debug, Clone, Copy)]
7095
pub struct ClassFlags: u32 {
96+
/// Final class or method
7197
const Final = ZEND_ACC_FINAL;
98+
/// Abstract method
7299
const Abstract = ZEND_ACC_ABSTRACT;
100+
/// Immutable `op_array` and class_entries
101+
/// (implemented only for lazy loading of `op_array`s)
73102
const Immutable = ZEND_ACC_IMMUTABLE;
103+
/// Function has typed arguments / class has typed props
74104
const HasTypeHints = ZEND_ACC_HAS_TYPE_HINTS;
105+
/// Top-level class or function declaration
75106
const TopLevel = ZEND_ACC_TOP_LEVEL;
107+
/// op_array or class is preloaded
76108
const Preloaded = ZEND_ACC_PRELOADED;
77109

110+
/// Class entry is an interface
78111
const Interface = ZEND_ACC_INTERFACE;
112+
/// Class entry is a trait
79113
const Trait = ZEND_ACC_TRAIT;
114+
/// Anonymous class
80115
const AnonymousClass = ZEND_ACC_ANON_CLASS;
116+
/// Class linked with parent, interfaces and traits
81117
const Linked = ZEND_ACC_LINKED;
118+
/// Class is abstract, since it is set by any abstract method
82119
const ImplicitAbstractClass = ZEND_ACC_IMPLICIT_ABSTRACT_CLASS;
120+
/// Class has magic methods `__get`/`__set`/`__unset`/`__isset` that use guards
83121
const UseGuards = ZEND_ACC_USE_GUARDS;
122+
123+
/// Class constants updated
84124
const ConstantsUpdated = ZEND_ACC_CONSTANTS_UPDATED;
125+
/// Objects of this class may not have dynamic properties
85126
const NoDynamicProperties = ZEND_ACC_NO_DYNAMIC_PROPERTIES;
127+
/// User class has methods with static variables
86128
const HasStaticInMethods = ZEND_HAS_STATIC_IN_METHODS;
129+
/// Children must reuse parent `get_iterator()`
87130
#[cfg(not(php82))]
88131
const ReuseGetIterator = ZEND_ACC_REUSE_GET_ITERATOR;
132+
/// Parent class is resolved (CE)
89133
const ResolvedParent = ZEND_ACC_RESOLVED_PARENT;
134+
/// Interfaces are resolved (CE)
90135
const ResolvedInterfaces = ZEND_ACC_RESOLVED_INTERFACES;
136+
/// Class has unresolved variance obligations
91137
const UnresolvedVariance = ZEND_ACC_UNRESOLVED_VARIANCE;
138+
/// Class is linked apart from variance obligations
92139
const NearlyLinked = ZEND_ACC_NEARLY_LINKED;
93140

141+
/// Class cannot be serialized or unserialized
94142
#[cfg(php81)]
95143
const NotSerializable = crate::ffi::ZEND_ACC_NOT_SERIALIZABLE;
96144
}
@@ -100,34 +148,67 @@ bitflags! {
100148
/// Flags for building methods.
101149
#[derive(PartialEq, Eq, PartialOrd, Ord, Hash, Debug, Clone, Copy)]
102150
pub struct MethodFlags: u32 {
151+
/// Visibility public
103152
const Public = ZEND_ACC_PUBLIC;
153+
/// Visibility protected
104154
const Protected = ZEND_ACC_PROTECTED;
155+
/// Visibility private
105156
const Private = ZEND_ACC_PRIVATE;
157+
/// Method or property overrides private one
106158
const Changed = ZEND_ACC_CHANGED;
159+
/// Static method
107160
const Static = ZEND_ACC_STATIC;
161+
/// Final method
108162
const Final = ZEND_ACC_FINAL;
163+
/// Abstract method
109164
const Abstract = ZEND_ACC_ABSTRACT;
165+
/// Immutable `op_array` and class_entries
166+
/// (implemented only for lazy loading of op_arrays)
110167
const Immutable = ZEND_ACC_IMMUTABLE;
168+
/// Function has typed arguments / class has typed props
111169
const HasTypeHints = ZEND_ACC_HAS_TYPE_HINTS;
170+
/// Top-level class or function declaration
112171
const TopLevel = ZEND_ACC_TOP_LEVEL;
172+
/// `op_array` or class is preloaded
113173
const Preloaded = ZEND_ACC_PRELOADED;
114174

175+
/// Deprecation flag
115176
const Deprecated = ZEND_ACC_DEPRECATED;
177+
/// Function returning by reference
116178
const ReturnReference = ZEND_ACC_RETURN_REFERENCE;
179+
/// Function has a return type
117180
const HasReturnType = ZEND_ACC_HAS_RETURN_TYPE;
181+
/// Function with variable number of arguments
118182
const Variadic = ZEND_ACC_VARIADIC;
183+
/// `op_array` has finally blocks (user only)
119184
const HasFinallyBlock = ZEND_ACC_HAS_FINALLY_BLOCK;
185+
/// "main" `op_array` with `ZEND_DECLARE_CLASS_DELAYED` opcodes
120186
const EarlyBinding = ZEND_ACC_EARLY_BINDING;
187+
/// Closure uses `$this`
121188
const UsesThis = ZEND_ACC_USES_THIS;
189+
/// Call through user function trampoline
190+
///
191+
/// # Example
192+
/// - `__call`
193+
/// - `__callStatic`
122194
const CallViaTrampoline = ZEND_ACC_CALL_VIA_TRAMPOLINE;
195+
/// Disable inline caching
123196
const NeverCache = ZEND_ACC_NEVER_CACHE;
197+
/// `op_array` is a clone of trait method
124198
const TraitClone = ZEND_ACC_TRAIT_CLONE;
199+
/// Function is a constructor
125200
const IsConstructor = ZEND_ACC_CTOR;
201+
/// Function is a closure
126202
const Closure = ZEND_ACC_CLOSURE;
203+
/// Function is a fake closure
127204
const FakeClosure = ZEND_ACC_FAKE_CLOSURE;
205+
/// Function is a generator
128206
const Generator = ZEND_ACC_GENERATOR;
207+
/// Function was processed by pass two (user only)
129208
const DonePassTwo = ZEND_ACC_DONE_PASS_TWO;
209+
/// `run_time_cache` allocated on heap (user only)
130210
const HeapRTCache = ZEND_ACC_HEAP_RT_CACHE;
211+
/// `op_array` uses strict mode types
131212
const StrictTypes = ZEND_ACC_STRICT_TYPES;
132213
}
133214
}
@@ -155,9 +236,13 @@ bitflags! {
155236
/// Flags for building constants.
156237
#[derive(PartialEq, Eq, PartialOrd, Ord, Hash, Debug, Clone, Copy)]
157238
pub struct ConstantFlags: u32 {
239+
/// Visibility public
158240
const Public = ZEND_ACC_PUBLIC;
241+
/// Visibility protected
159242
const Protected = ZEND_ACC_PROTECTED;
243+
/// Visibility private
160244
const Private = ZEND_ACC_PRIVATE;
245+
/// Promoted constant
161246
const Promoted = ZEND_ACC_PROMOTED;
162247
}
163248
}
@@ -166,9 +251,14 @@ bitflags! {
166251
/// Flags for building module global constants.
167252
#[derive(PartialEq, Eq, PartialOrd, Ord, Hash, Debug, Clone, Copy)]
168253
pub struct GlobalConstantFlags: u32 {
254+
/// No longer used -- always case-sensitive
255+
#[deprecated(note = "No longer used -- always case-sensitive")]
169256
const CaseSensitive = CONST_CS;
257+
/// Persistent
170258
const Persistent = CONST_PERSISTENT;
259+
/// Can't be saved in file cache
171260
const NoFileCache = CONST_NO_FILE_CACHE;
261+
/// Deprecated (this flag is not deprecated, it literally means the constant is deprecated)
172262
const Deprecated = CONST_DEPRECATED;
173263
}
174264
}
@@ -177,46 +267,71 @@ bitflags! {
177267
/// Represents the result of a function.
178268
#[derive(PartialEq, Eq, PartialOrd, Ord, Hash, Debug, Clone, Copy)]
179269
pub struct ZendResult: i32 {
270+
/// Function call was successful.
180271
const Success = 0;
272+
/// Function call failed.
181273
const Failure = -1;
182274
}
183275
}
184276

185277
bitflags! {
186278
/// Represents permissions for where a configuration setting may be set.
187279
pub struct IniEntryPermission: u32 {
280+
/// User
188281
const User = PHP_INI_USER;
282+
/// Per directory
189283
const PerDir = PHP_INI_PERDIR;
284+
/// System
190285
const System = PHP_INI_SYSTEM;
286+
/// All
191287
const All = PHP_INI_ALL;
192288
}
193289
}
194290

195291
bitflags! {
196292
/// Represents error types when used via php_error_docref for example.
197293
pub struct ErrorType: u32 {
294+
/// Error
198295
const Error = E_ERROR;
296+
/// Warning
199297
const Warning = E_WARNING;
298+
/// Parse
200299
const Parse = E_PARSE;
300+
/// Notice
201301
const Notice = E_NOTICE;
302+
/// Core error
202303
const CoreError = E_CORE_ERROR;
304+
/// Core warning
203305
const CoreWarning = E_CORE_WARNING;
306+
/// Compile error
204307
const CompileError = E_COMPILE_ERROR;
308+
/// Compile warning
205309
const CompileWarning = E_COMPILE_WARNING;
310+
/// User error
206311
const UserError = E_USER_ERROR;
312+
/// User warning
207313
const UserWarning = E_USER_WARNING;
314+
/// User notice
208315
const UserNotice = E_USER_NOTICE;
316+
/// Strict
209317
const Strict = E_STRICT;
318+
/// Recoverable error
210319
const RecoverableError = E_RECOVERABLE_ERROR;
320+
/// Deprecated
211321
const Deprecated = E_DEPRECATED;
322+
/// User deprecated
212323
const UserDeprecated = E_USER_DEPRECATED;
213324
}
214325
}
215326

327+
/// Represents the type of a function.
216328
#[derive(PartialEq, Eq, Hash, Debug, Clone, Copy)]
217329
pub enum FunctionType {
330+
/// Internal function
218331
Internal,
332+
/// User function
219333
User,
334+
/// Eval code
220335
Eval,
221336
}
222337

@@ -236,24 +351,43 @@ impl From<u8> for FunctionType {
236351
#[repr(C, u8)]
237352
#[derive(Debug, Clone, Copy, PartialEq, Eq, PartialOrd, Ord)]
238353
pub enum DataType {
354+
/// Undefined
239355
Undef,
356+
/// `null`
240357
Null,
358+
/// `false`
241359
False,
360+
/// `true`
242361
True,
362+
/// Integer (the irony)
243363
Long,
364+
/// Floating point number
244365
Double,
366+
/// String
245367
String,
368+
/// Array
246369
Array,
370+
/// Iterable
247371
Iterable,
372+
/// Object
248373
Object(Option<&'static str>),
374+
/// Resource
249375
Resource,
376+
/// Reference
250377
Reference,
378+
/// Callable
251379
Callable,
380+
/// Constant expression
252381
ConstantExpression,
382+
/// Void
253383
Void,
384+
/// Mixed
254385
Mixed,
386+
/// Boolean
255387
Bool,
388+
/// Pointer
256389
Ptr,
390+
/// Indirect (internal)
257391
Indirect,
258392
}
259393

src/props.rs

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -59,20 +59,21 @@ impl<'a, T: Clone + IntoZval + FromZval<'a>> Prop<'a> for T {
5959
}
6060
}
6161

62+
/// A getter for a property
6263
pub type PropertyGetter<'a, T> = Option<Box<dyn Fn(&T, &mut Zval) -> PhpResult + Send + Sync + 'a>>;
64+
/// A setter for a property
6365
pub type PropertySetter<'a, T> = Option<Box<dyn Fn(&mut T, &Zval) -> PhpResult + Send + Sync + 'a>>;
6466

6567
/// Represents a property added to a PHP class.
66-
///
67-
/// There are two types of properties:
68-
///
69-
/// * Field properties, where the data is stored inside a struct field.
70-
/// * Method properties, where getter and/or setter functions are provided,
71-
/// which are used to get and set the value of the property.
7268
pub enum Property<'a, T> {
69+
/// Field properties, where the data is stored inside a struct field.
7370
Field(Box<dyn (Fn(&mut T) -> &mut dyn Prop) + Send + Sync>),
71+
/// Method properties, where getter and/or setter functions are provided,
72+
/// which are used to get and set the value of the property.
7473
Method {
74+
/// Getter function for the property.
7575
get: PropertyGetter<'a, T>,
76+
/// Setter function for the property.
7677
set: PropertySetter<'a, T>,
7778
},
7879
}

0 commit comments

Comments
 (0)