code: @SuppressWarnings("unchecked")
      public static <T extends TestRule> Optional<T> getAttachedRule(RuleChain ruleChain, Class<T> ruleType) {
          for (TestRule rule : getRuleList(ruleChain)) {
              if (rule.getClass() == ruleType) {
                  return Optional.of((T) rule);
              }
          }
          return Optional.absent();
      }
docs: Get reference to an instance of the specified test rule type on the supplied rule chain.
  
  @param <T> test rule type
  @param ruleChain rule chain to be walked
  @param ruleType test rule type
  @return optional test rule instance