Skip to content
This repository has been archived by the owner on Nov 12, 2023. It is now read-only.

Commit

Permalink
Update code style (attributes after doc comments) (#95)
Browse files Browse the repository at this point in the history
  • Loading branch information
Antikyth authored Jan 25, 2023
2 parents 22b8e17 + 8c7cddc commit a630355
Show file tree
Hide file tree
Showing 6 changed files with 307 additions and 274 deletions.
35 changes: 34 additions & 1 deletion CONTRIBUTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,40 @@ examples would be comparing the events in the events section of the
[`x11::event`]: https://github.com/XdotRS/xrb/blob/main/src/x11/event.rs

## Code style
TODO

### Placement of attributes
Many types and fields in XRB use attributes. To keep the source code consistent and easily readable, attributes should be put _after_ doc comments.

For example, do this:
```rust
/// A foo which does bar.
#[doc(alias = "baz")]
#[derive(Debug, Hash, X11Size)]
pub struct Foo {
/// Data which represents xyz.
#[custom_attribute]
pub data: Any,

/// The other field within this `Foo`.
pub other_field: Any,
}
```
But **not** this:
```rust
#[derive(Debug, Hash, X11Size)]
/// A foo which does bar.
#[doc(alias = "baz")]
pub struct DoNotDoThis {
#[custom_attribute]
/// Data which represents xyz.
pub data: Any,

/// The other field within this `DoNotDoThis`.
pub other_field: Any,
}
```

This consistently groups related syntax together - you know you'll always find the attributes after the documentation, if the documentation is quite long for example, and that you're looking at all of the attributes at once.

## Useful resources
- [X Window System protocol version 11](https://x.org/releases/X11R7.7/doc/xproto/x11protocol.html)
Expand Down
2 changes: 1 addition & 1 deletion src/common.rs
Original file line number Diff line number Diff line change
Expand Up @@ -104,10 +104,10 @@ pub enum WindowGravity {

// The `derive_xrb!` attribute here is used to write the discriminants as `u16`.
derive_xrb! {
#[derive(Copy, Clone, Eq, PartialEq, Hash, Debug, X11Size, Readable, Writable)]
/// A [window]'s class; whether it has a visual output form.
///
/// [window]: Window
#[derive(Copy, Clone, Eq, PartialEq, Hash, Debug, X11Size, Readable, Writable)]
pub enum WindowClass: u16 {
/// A [window] that both receives input and has a visual output (i.e. what
/// one would normally consider a window to be).
Expand Down
6 changes: 3 additions & 3 deletions src/connection.rs
Original file line number Diff line number Diff line change
Expand Up @@ -88,8 +88,8 @@ impl ConnectionResponse {
}

derive_xrb! {
#[derive(Debug, X11Size, Readable, Writable)]
/// There was a failure in attempting the connection.
#[derive(Debug, X11Size, Readable, Writable)]
pub struct ConnectionFailure {
#[allow(clippy::cast_possible_truncation)]
let reason_len: u8 = reason => reason.len() as u8,
Expand All @@ -112,8 +112,8 @@ derive_xrb! {
[_; ..],
}

#[derive(Debug, X11Size, Readable, Writable)]
/// The connection was successfully established.
#[derive(Debug, X11Size, Readable, Writable)]
pub struct ConnectionSuccess {
_,
/// The major version of the X11 protocol used by the X server.
Expand Down Expand Up @@ -165,8 +165,8 @@ derive_xrb! {
pub roots: Vec<Screen>,
}

#[derive(Debug, X11Size, Readable, Writable)]
/// The connection was refused because authentication was unsuccessful.
#[derive(Debug, X11Size, Readable, Writable)]
pub struct ConnectionAuthenticationError {
[_; 5],

Expand Down
8 changes: 4 additions & 4 deletions src/message.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,8 @@
use crate::x11::error;
use xrbk::{Readable, Writable, X11Size};

#[doc(notable_trait)]
/// A message sent from an X client to the X server.
#[doc(notable_trait)]
pub trait Request: X11Size + Writable {
/// The type representing the [other possible errors][other-errors]
/// generated by this `Request`.
Expand Down Expand Up @@ -209,9 +209,9 @@ pub enum RequestError<OtherErrors> {
Other(OtherErrors),
}

#[doc(notable_trait)]
/// A message sent from the X server to an X client in response to a
/// [`Request`].
#[doc(notable_trait)]
pub trait Reply: X11Size + Readable {
/// The [request] that generates this `Reply`.
///
Expand Down Expand Up @@ -319,14 +319,14 @@ pub trait Reply: X11Size + Readable {
fn sequence(&self) -> u16;
}

#[doc(notable_trait)]
/// A message sent from the X server to an X client.
///
/// `Event`s differ from [replies] in that they are not a direct response to a
/// [request] sent by the client receiving them.
///
/// [replies]: Reply
/// [request]: Request
#[doc(notable_trait)]
pub trait Event: X11Size + Readable + Writable {
/// The code uniquely identifying this `Event` (among other `Event`s).
///
Expand All @@ -342,11 +342,11 @@ pub trait Event: X11Size + Readable + Writable {
fn sequence(&self) -> Option<u16>;
}

#[doc(notable_trait)]
/// An error sent from the X server to an X client in response to a failed
/// [request].
///
/// [request]: Request
#[doc(notable_trait)]
pub trait Error: X11Size + Readable {
/// The code uniquely identifying this `Error` (among other `Error`s).
///
Expand Down
Loading

0 comments on commit a630355

Please sign in to comment.