diff --git a/.github/workflows/rustfmt.yml b/.github/workflows/rustfmt.yml
new file mode 100644
index 0000000..1215725
--- /dev/null
+++ b/.github/workflows/rustfmt.yml
@@ -0,0 +1,20 @@
+on: [push, pull_request]
+
+name: Code formatting check
+
+jobs:
+  fmt:
+    name: Rustfmt
+    runs-on: ubuntu-latest
+    steps:
+      - uses: actions/checkout@v2
+      - uses: actions-rs/toolchain@v1
+        with:
+          profile: minimal
+          toolchain: stable
+          override: true
+      - run: rustup component add rustfmt
+      - uses: actions-rs/cargo@v1
+        with:
+          command: fmt
+          args: --all -- --check
diff --git a/build.rs b/build.rs
index 4f4a6d6..315035e 100644
--- a/build.rs
+++ b/build.rs
@@ -11,7 +11,8 @@ fn main() {
             fs::copy(
                 format!("bin/{}.a", target),
                 out_dir.join(format!("lib{}.a", name)),
-            ).unwrap();
+            )
+            .unwrap();
 
             println!("cargo:rustc-link-lib=static={}", name);
             println!("cargo:rustc-link-search={}", out_dir.display());
diff --git a/src/hio.rs b/src/hio.rs
index 61ac749..10e937b 100644
--- a/src/hio.rs
+++ b/src/hio.rs
@@ -1,7 +1,7 @@
 //! Host I/O
 
-use core::{fmt, slice};
 use crate::nr;
+use core::{fmt, slice};
 
 /// Host's standard error
 #[derive(Clone, Copy)]
@@ -57,8 +57,7 @@ pub fn hstdout() -> Result<HStdout, ()> {
 
 fn open(name: &str, mode: usize) -> Result<usize, ()> {
     let name = name.as_bytes();
-    match unsafe { syscall!(OPEN, name.as_ptr(), mode, name.len() - 1) } as
-        isize {
+    match unsafe { syscall!(OPEN, name.as_ptr(), mode, name.len() - 1) } as isize {
         -1 => Err(()),
         fd => Ok(fd as usize),
     }
@@ -72,9 +71,7 @@ fn write_all(fd: usize, mut buffer: &[u8]) -> Result<(), ()> {
             // `n` bytes were not written
             n if n <= buffer.len() => {
                 let offset = (buffer.len() - n) as isize;
-                buffer = unsafe {
-                    slice::from_raw_parts(buffer.as_ptr().offset(offset), n)
-                }
+                buffer = unsafe { slice::from_raw_parts(buffer.as_ptr().offset(offset), n) }
             }
             #[cfg(feature = "jlink-quirks")]
             // Error (-1) - should be an error but JLink can return -1, -2, -3,...
diff --git a/src/macros.rs b/src/macros.rs
index 9aaceef..37748ce 100644
--- a/src/macros.rs
+++ b/src/macros.rs
@@ -11,12 +11,13 @@ macro_rules! syscall {
         $crate::syscall($crate::nr::$nr, &[$a1 as usize, $a2 as usize])
     };
     ($nr:ident, $a1:expr, $a2:expr, $a3:expr) => {
-        $crate::syscall($crate::nr::$nr, &[$a1 as usize, $a2 as usize,
-                                           $a3 as usize])
+        $crate::syscall($crate::nr::$nr, &[$a1 as usize, $a2 as usize, $a3 as usize])
     };
     ($nr:ident, $a1:expr, $a2:expr, $a3:expr, $a4:expr) => {
-        $crate::syscall($crate::nr::$nr, &[$a1 as usize, $a2 as usize,
-                                           $a3 as usize, $a4 as usize])
+        $crate::syscall(
+            $crate::nr::$nr,
+            &[$a1 as usize, $a2 as usize, $a3 as usize, $a4 as usize],
+        )
     };
 }