Skip to content

Commit 919cbf5

Browse files
committed
Update docs for conditional compilation
- Update README to explain the versioning - Add attributes that make conditional features stand out in the generated rustdocs. This relies on an experimental `doc_cfg` compiler feature which doesn't exist on stable, so opt into it with a `dox` feature in i3ipc-rs that can be enabled for documentation builds.
1 parent 5ea59da commit 919cbf5

File tree

6 files changed

+32
-5
lines changed

6 files changed

+32
-5
lines changed

Cargo.toml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,3 +16,5 @@ serde_json = "0.6.0"
1616
i3-4-12 = []
1717
i3-4-13 = ["i3-4-12"]
1818
i3-4-14 = ["i3-4-13"]
19+
i3-next = ["i3-4-14"]
20+
dox = ["i3-next"]

README.md

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -10,8 +10,8 @@ A Rust library for controlling i3-wm through its [IPC interface](https://i3wm.or
1010
## Usage
1111
Add this to your Cargo.toml
1212
```toml
13-
[dependencies]
14-
i3ipc = "0.7.0"
13+
[dependencies.i3ipc]
14+
version = "0.7.0"
1515
```
1616

1717
## Messages:
@@ -59,8 +59,14 @@ fn main() {
5959
}
6060
```
6161

62-
## Compatibility
62+
## Versioning
6363

64-
This library was last updated for **i3 version 4.11**, but is forward compatible. Contributions are welcome!
64+
By default i3ipc-rs targets minimum i3 version 4.11. To unlock additional features you can increase this by selecting one of `"i3-4-12"`, ..., `"i3-4-14"` in Cargo.toml.
6565

66-
All documented functionality from i3 version 4.11 can be handled by this library. Additions to the i3 IPC interface that are not understood by this library will generally return an `Unknown` value and log a warning to the target `"i3ipc"` using the [log crate](http://doc.rust-lang.org/log). Binaries using this library should [install a logger](https://doc.rust-lang.org/log/log/index.html#in-executables) to view details of such additions.
66+
```
67+
[dependencies.i3ipc]
68+
version = "0.7.0"
69+
features = ["i3-4-14"]
70+
```
71+
72+
Additions to the i3 IPC interface that are not understood by your compiled binary will generally return an `Unknown` value and log a warning to the target `"i3ipc"` using the [log crate](http://doc.rust-lang.org/log). Binaries using this library should [install a logger](https://doc.rust-lang.org/log/log/index.html#in-executables) to view details of such additions.

src/common.rs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -112,12 +112,15 @@ pub fn build_bar_config(j: &json::Value) -> reply::BarConfig {
112112
"separator" => reply::ColorableBarPart::Separator,
113113

114114
#[cfg(feature = "i3-4-12")]
115+
#[doc(cfg(feature = "i3-4-12"))]
115116
"focused_background" => reply::ColorableBarPart::FocusedBackground,
116117

117118
#[cfg(feature = "i3-4-12")]
119+
#[doc(cfg(feature = "i3-4-12"))]
118120
"focused_statusline" => reply::ColorableBarPart::FocusedStatusline,
119121

120122
#[cfg(feature = "i3-4-12")]
123+
#[doc(cfg(feature = "i3-4-12"))]
121124
"focused_separator" => reply::ColorableBarPart::FocusedSeparator,
122125

123126
"focused_workspace_text" => reply::ColorableBarPart::FocusedWorkspaceText,

src/event.rs

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ pub enum Event {
1818
BindingEvent(BindingEventInfo),
1919

2020
#[cfg(feature = "i3-4-14")]
21+
#[doc(cfg(feature = "i3-4-14"))]
2122
ShutdownEvent(ShutdownEventInfo),
2223
}
2324

@@ -136,6 +137,7 @@ impl FromStr for WindowEventInfo {
136137
"urgent" => WindowChange::Urgent,
137138

138139
#[cfg(feature = "i3-4-13")]
140+
#[doc(cfg(feature = "i3-4-13"))]
139141
"mark" => WindowChange::Mark,
140142

141143
other => {
@@ -217,11 +219,13 @@ impl FromStr for BindingEventInfo {
217219
/// Data for `ShutdownEvent`.
218220
#[derive(Debug)]
219221
#[cfg(feature = "i3-4-14")]
222+
#[doc(cfg(feature = "i3-4-14"))]
220223
pub struct ShutdownEventInfo {
221224
pub change: ShutdownChange,
222225
}
223226

224227
#[cfg(feature = "i3-4-14")]
228+
#[doc(cfg(feature = "i3-4-14"))]
225229
impl FromStr for ShutdownEventInfo {
226230
type Err = json::error::Error;
227231
fn from_str(s: &str) -> Result<Self, Self::Err> {
@@ -285,6 +289,7 @@ pub mod inner {
285289

286290
/// A mark has been added to or removed from the window.
287291
#[cfg(feature = "i3-4-13")]
292+
#[doc(cfg(feature = "i3-4-13"))]
288293
Mark,
289294

290295
/// A WindowChange we don't support yet.
@@ -333,6 +338,7 @@ pub mod inner {
333338
/// The kind of shutdown change.
334339
#[derive(Debug)]
335340
#[cfg(feature = "i3-4-14")]
341+
#[doc(cfg(feature = "i3-4-14"))]
336342
pub enum ShutdownChange {
337343
Restart,
338344
Exit,

src/lib.rs

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,8 @@
1515
//! This library should cover all of i3's documented ipc features. If it's missing something
1616
//! please open an issue on github.
1717
18+
#![cfg_attr(feature = "dox", feature(doc_cfg))]
19+
1820
extern crate unix_socket;
1921
extern crate byteorder;
2022
#[macro_use]
@@ -180,6 +182,7 @@ impl<'a> Iterator for EventIterator<'a> {
180182
5 => event::Event::BindingEvent(try!(event::BindingEventInfo::from_str(payload))),
181183

182184
#[cfg(feature = "i3-4-14")]
185+
#[doc(cfg(feature = "i3-4-14"))]
183186
6 => event::Event::ShutdownEvent(try!(event::ShutdownEventInfo::from_str(payload))),
184187

185188
_ => unreachable!("received an event we aren't subscribed to!")
@@ -211,6 +214,7 @@ pub enum Subscription {
211214
BarConfig,
212215
Binding,
213216
#[cfg(feature = "i3-4-14")]
217+
#[doc(cfg(feature = "i3-4-14"))]
214218
Shutdown,
215219
}
216220

@@ -247,6 +251,7 @@ impl I3EventListener {
247251
Subscription::BarConfig => "\"barconfig_update\"",
248252
Subscription::Binding => "\"binding\"",
249253
#[cfg(feature = "i3-4-14")]
254+
#[doc(cfg(feature = "i3-4-14"))]
250255
Subscription::Shutdown => "\"shutdown\""})
251256
.collect::<Vec<_>>()
252257
.join(", ")[..]
@@ -478,6 +483,7 @@ impl I3Connection {
478483

479484
/// Gets the list of currently configured binding modes.
480485
#[cfg(feature = "i3-4-13")]
486+
#[doc(cfg(feature = "i3-4-13"))]
481487
pub fn get_binding_modes(&mut self) -> Result<reply::BindingModes, MessageError> {
482488
if let Err(e) = self.stream.send_i3_message(8, "") {
483489
return Err(MessageError::Send(e));

src/reply.rs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -221,16 +221,19 @@ pub enum ColorableBarPart {
221221

222222
/// Background color of the bar on the currently focused monitor output.
223223
#[cfg(feature = "i3-4-12")]
224+
#[doc(cfg(feature = "i3-4-12"))]
224225
FocusedBackground,
225226

226227
/// Text color to be used for the statusline on the currently focused
227228
/// monitor output.
228229
#[cfg(feature = "i3-4-12")]
230+
#[doc(cfg(feature = "i3-4-12"))]
229231
FocusedStatusline,
230232

231233
/// Text color to be used for the separator on the currently focused
232234
/// monitor output.
233235
#[cfg(feature = "i3-4-12")]
236+
#[doc(cfg(feature = "i3-4-12"))]
234237
FocusedSeparator,
235238

236239
/// Text color for a workspace button when the workspace has focus.
@@ -357,6 +360,7 @@ pub struct Version {
357360

358361
/// The reply to the `get_binding_modes` request.
359362
#[cfg(feature = "i3-4-13")]
363+
#[doc(cfg(feature = "i3-4-13"))]
360364
#[derive(Debug)]
361365
pub struct BindingModes {
362366
/// A vector of all currently configured binding modes.

0 commit comments

Comments
 (0)