           (pop-to-buffer (current-buffer)))
       (message "rustfmt check passed."))))
 
-(defun rust-format-buffer ()
-  "Format the current buffer using rustfmt."
-  (interactive)
-  (unless (executable-find rust-rustfmt-bin)
-    (error "Could not locate executable \"%s\"" rust-rustfmt-bin))
-
+(defun rust--format-buffer-using-replace-buffer-contents ()
+  (condition-case err
+      (progn
+        (rust--format-call (current-buffer))
+        (message "Formatted buffer with rustfmt."))
+    (error
+     (or (rust--format-error-handler)
+         (signal (car err) (cdr err))))))
+
+(defun rust--format-buffer-saving-position-manually ()
   (let* ((current (current-buffer))
          (base (or (buffer-base-buffer current) current))
          buffer-loc

      (error
       (or (rust--format-error-handler)
           (signal (car err) (cdr err)))))))

(defun rust-enable-format-on-save ()
  "Enable formatting using rustfmt when saving buffer."

             ((zerop ret)
              (if (not (string= (buffer-string)
                                (with-current-buffer buf (buffer-string))))
                  ;; replace-buffer-contents was in emacs 26.1, but it
                  ;; was broken for non-ASCII strings, so we need 26.2.
                  (if (and (fboundp 'replace-buffer-contents)
                           (version<= "26.2" emacs-version))
                      (with-current-buffer buf
                        (replace-buffer-contents rust-rustfmt-buffername))
                    (copy-to-buffer buf (point-min) (point-max))))
              (kill-buffer))
             ((= ret 3)
              (if (not (string= (buffer-string)
